?
Solved

VBA to sort after select

Posted on 2014-04-10
3
Medium Priority
?
324 Views
Last Modified: 2014-04-10
I am using the below code to select a range. The range will change each time it is used.

Range("A1").CurrentRegion.Select

I need to then be able to sort on column Z but not sure how to do this as the range changes.

Can an expert help me out with this please.

Thanks
0
Comment
Question by:Jagwarman
  • 2
3 Comments
 

Author Comment

by:Jagwarman
ID: 39991057
Just to clarify. I will always use Range("A1").CurrentRegion.Select

the region may be from A1 to Z100 one day and A1 to Z600 another etc
0
 
LVL 54

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 39991070
HI,

You could use

Set myRange = Range("A1").CurrentRegion
myRange.Sort Key1:=Range("Z1"), Order1:=xlAscending, Header:=xlYes

Open in new window


or maybe

Range("A1").CurrentRegion.Select
Selection.Sort Key1:=Range("Z1"), Order1:=xlAscending, Header:=xlYes

Open in new window

Regards
0
 

Author Closing Comment

by:Jagwarman
ID: 39991119
Exellent you always come up with a solution for me Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question