Hi, brand new to the forum. Not a newbie, but somewhat experienced with simpler code.
Here's my problem. I want to use the last cell with data as part of the range in an ActiveSheet.Sort.SortFields.Add Key:=Range( ??? statement.
I got this far and stored row and column to variables, but can't get a cell address to place in the sort statement.
Dim lastRow As Long
Dim lastColumn As Integer
Dim lastCell As Range
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
lastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
'Search for any entry, by searching backwards by Columns.
lastColumn = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
MsgBox Cells(lastRow, lastColumn).Address
Set lastCell = Cells(lastColumn, lastRow)
The message box displays $U$711905 and lastRow is set to 711905 and lastColumn is set to 21, but lastCell = Nothing
Thanks for any help you can offer.
Here's my problem. I want to use the last cell with data as part of the range in an ActiveSheet.Sort.SortFields.Add Key:=Range( ??? statement.
I got this far and stored row and column to variables, but can't get a cell address to place in the sort statement.
Dim lastRow As Long
Dim lastColumn As Integer
Dim lastCell As Range
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
lastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
'Search for any entry, by searching backwards by Columns.
lastColumn = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
MsgBox Cells(lastRow, lastColumn).Address
Set lastCell = Cells(lastColumn, lastRow)
The message box displays $U$711905 and lastRow is set to 711905 and lastColumn is set to 21, but lastCell = Nothing
Thanks for any help you can offer.