I use this code to get the last row number.
Dim sh As Worksheet: Set sh = ActiveSheet
Dim lastRow As Long
lastRow = sh.Cells.Find("*", LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
I need to convert it into a function, I tried the following but the output is always 0.
Function LR(sh As Worksheet) As Long
Dim lastRow As Long, LastColumn As Long
lastRow = sh.Cells.Find("*", LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End Function
And using like this
Dim i As Long: i = LR(ActiveSheet)
Debug.Print i