ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I macro sort with a varaible range (differing last cell)? (https://www.excelbanter.com/excel-programming/400770-how-do-i-macro-sort-varaible-range-differing-last-cell.html)

sutibusan

How do I macro sort with a varaible range (differing last cell)?
 
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).

Dave Peterson

How do I macro sort with a varaible range (differing last cell)?
 
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

sutibusan wrote:

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).


--

Dave Peterson

FSt1

How do I macro sort with a varaible range (differing last cell)?
 
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

"sutibusan" wrote:

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).



All times are GMT +1. The time now is 01:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com