How do I macro sort with a varaible range (differing last cell)?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to sort from A3 to J100, for example, now. Later, it could be from A3
to J207. There usually are blank columns also (the LIST command didn't like
that).
 
Can you pick out a column that always has data in it if that row is used?

Maybe...

Dim LastRow as long
with worksheets("somesheetname")
lastrow = .cells(.rows.count,"A").end(xlup).row

.range("a3:J" & lastrow).sort ...rest of sort parms here...
End with
 
hi
find the last row.
dim r as range
lr = cells(Rows.Count, "A").End(xlUp).Row
set r = range("A3:J" & lr)
r.Sort Key1:=Range("A3"), _ 'or what you have
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

regards
FSt1
 

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

Back
Top