Finding Last Cell that Has Data
I assume you know how many columns wide you are sorting. I also assume that
your data populates all the way to the bottom of column A (if not then we
need to get a bit more fancy)... You just need to change the "??" to
whichever is your last column...
Private Sub cmdSort_Click()
Dim rngToSort As Range
Dim wks As Worksheet
Set wks = Sheets("XYZ")
Set rngToSort = Range("??3",Cells(Rows.Count, "A").End(xlUp))
rngToSort.Sort Key1:=Range("A3"), order1:=xlAscending, Header:=xlNo
End Sub
--
HTH...
Jim Thomlinson
"caldog" wrote:
I have search through prior posting of how to find last row, then sort from
that information, But I must be doing something wrong becasue I still get a
error message. Also the first cell will always be 'A3'.
Here is the code that I have put together:
Private Sub cmdSort_Click()
Dim rngToSort As Range
Dim LastRow As Long
Dim wks As Worksheet
Set wks = Sheets("XYZ")
Set rngToSort = Range("A3",LastRow = Cells(Rows.Count, "A").End(xlUp).Row)
As Range
rngToSort.Sort Key1:=Range("A3"), order1:=xlAscending, Header:=xlNo
End Sub
Can somebody show me what I'm doing wrong.
Steve
|