Help with Sort

G

Glen Mettler

I want to sort a section of a spreadsheet -
I make a selection (say range("A22:D27")
I then want to sort that selection on column c then column d

when I recorded the macro this is what I got:
Range("A22:D27").Select
Selection.Sort Key1:=Range("C22"), Order1:=xlAscending,
Key2:=Range("D22" _
), Order2:=xlAscending, Header:=xlNo, OrderCustom:=1,
MatchCase:=False _
, Orientation:=xlTopToBottom
The problem is that the range is hard coded with "C22" - I want a variable
so I can select a range and then sort by column c then column d
How can I capture the top row number of the range so I can have this as a
dynamic macro?

Glen
 

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