If you want to find the last cell in a book other than ThisWorkbook
:
Function FindingLastRow( _
ByVal shtName As String, _
Optional ByVal colLetter As Variant, _
Optional ByRef wkBk As Variant _
) As Long
Dim colId As String
If IsMissing(colLetter) Then
colId = "A"
Else
colId = colLetter
End If
Dim myTargBk As Excel.Workbook
If IsMissing(wkBk) Then
Set myTargBk = ThisWorkbook
Else
Set myTargBk = wkBk
End If
Dim sht As Worksheet
Set sht = myTargBk.Worksheets(shtName)
With sht
FindingLastRow = .Cells(.Rows.Count, colId).End(Excel.xlUp).Row
End With
End Function
Used like this:
Sub findLast()
MsgBox FindingLastRow("Sheet1")
End Sub
Or to find the last row of column A in a different open workbook...
Sub findLast2()
Dim w As Excel.Workbook
Set w = Excel.Workbooks("Norf.xlsx")
MsgBox FindingLastRow("Sheet1", , w)
End Sub
Or to find the last row of column B in a different open workbook...
Sub findLast3()
Dim w As Excel.Workbook
Set w = Excel.Workbooks("Norf.xlsx")
MsgBox FindingLastRow("Sheet1", "B", w)
End Sub