Thread: automatic sort
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
John Wilson John Wilson is offline
external usenet poster
 
Posts: 550
Default automatic sort

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

GUS wrote:

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