Finding the Last row on Excel sheet with VBA Macro
Below is the quick VBA code which you can be used to return the last row on an Excel sheet.
Simply call this function using "=" in Excel sheet or this function can be called anywhere in the VBA code.
Please note that for this code to work you would need to place this in any of the modules and not in the sheet or workbook specific code.
------------------------------------------------------
Function LastRow(Sh As Worksheet)
Dim varFound As Range
On Error Resume Next
Set varFound = Sh.Cells.Find(What:="*", LookIn:=xlValues, _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
If varFound.HasFormula Then
Do: Set varFound = Sh.Cells.FindPrevious(varFound)
Loop Until varFound.HasFormula = False
End If
LastRow = varFound.Row
On Error GoTo 0
End Function
-----------------------------------------------------
- Support's blog
- Login or register to post comments
