I like to pick out a column that always has data in it if the row is used. And
I use a row that always has data in it if the column is used (like headers in
row 1).
In this sample, I used column A and row 1:
Option Explicit
Sub Testme()
Dim LastRow as long
Dim LastCol as long
dim wks as worksheet
dim myRng as range
set wks = worksheets("somesheetnamehere")
with wks
lastrow = .cells(.rows.count,"A").end(xlup).row
lastcol = .cells(1, .columns.count).end(xltoleft).column
set myrng = .range("A1", .cells(lastrow, lastcol))
end with
with myrng
.sort key1:=.columns(1), order1:=xlAscending, _
Header:=xlYes, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
end with
End with
I like this technique from Debra Dalgleish's site:
http://contextures.com/xlSort02.html#Rectangles
Sort With Invisible Rectangles