Solved

VBA to sort after select

Posted on 2014-04-10
3
291 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
Comment Utility
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 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
Comment Utility
Exellent you always come up with a solution for me Thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
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…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

7 Experts available now in Live!

Get 1:1 Help Now