Find the last used Row on a Worksheet
This was my solution last week. It take a couple of seconds to run, but it
is a straight forward way of finding last row that I can remember. I don't
like to remember code unless I use it often.
Sub Lastrow()
For RowCount = Rows.Count To 1 Step -1
LastCol = Cells(RowCount, Columns.Count).End(xlToLeft).Column
If (LastCol < 1) Or (Not IsEmpty(Cells(RowCount, "A"))) Then
Exit For
End If
Next RowCount
MyLastRow = RowCount
End Sub
"kirkm" wrote:
Here's an example I found on the web
---
Find the last used Row on a Worksheet:
Sub FindLastRow()
Dim LastRow As Long
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
MsgBox LastRow
End If
End Sub
---
How do you tell Sub FindLastRow what worksheet to use ?
Also, is the above an OK method ?
Thanks - Kirk
|