automatic sort

G

GUS

I want a macro to automaticly read used columns and then sort the range
with column 1
For example if i have data like this
a b c d
1 gus italy 22 april
2 jim spain 34 may
3 david france 45 june


i don't want to give the range for sort at vba by myself.
I want code to automaticaly define the used range and then sort with the
next code

Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
 
J

John Wilson

Gus,

You can use CurrentRegion for your sort range.
Based on what you describe, it may just do the trick.
Check VBA Help for CurrentRegion to be sure.

Anyway.....
Range("A1").CurrentRegion.Sort Key1:=Range("B1"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top