Solved

VBA to sort after select

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
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…

914 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now