?
Solved

VBA to sort after select

Posted on 2014-04-10
3
Medium Priority
?
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 52

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

741 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