I wrote a function to find last row through it. I receive error when i run the sub. What i did is as follows:
Sub test()
Msgbox LROW(1,1)
End Sub
Function LROW(shtNumber as Integer, Col As Integer) as string
Dim shtName as string
ShtName="Sheet" & shtNumber
LROW=ShtName . Cells(rows.count, col).End(xlUp).Row
End Function
I recieve "invalid qualufier" error. Can anyone help please?
CodePudding user response:
ShtName
is a String (that holds the name of a sheet), not a sheet.
Use something like
Dim shtName as string
ShtName="Sheet" & shtNumber
Dim ws as Worksheet
Set ws = Worksheets(ShtName) ' Consider to use ThisWorkbook.Worksheets(ShtName)
LROW = ws.Cells(rows.count, col).End(xlUp).Row