How to find last row in an Excel sheet with Macro VBA

I am sure, many a times you want the VBA code to automatically find you the last row which is blank in a particular worksheet.

The Public Function below can be used to find the last row in a sheet. All you want to do is to put this in a module and call it when required passing sheet as an argument.

---------------------------------------------------
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
----------------------------------------------------