Solved

VBA to sort after select

Posted on 2014-04-10
3
297 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 49

Accepted Solution

by:
Rgonzo1971 earned 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

831 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