GetLastUsedRowNumberInWorksheet

GetLastUsedRowNumberInWorksheet

Function GetLastUsedRowNumberInWorksheet( _
    ws As Worksheet _
) As Long
    Dim _
        rng As Range, _
        rngResults As Range
    Set rng = _
        ws.Cells
    Set rngResults = _
        rng.Find( _
            what:="*", _
            After:=rng.Cells(1), _
            Lookat:=xlPart, _
            LookIn:=xlFormulas, _
            SearchOrder:=xlByRows, _
            SearchDirection:=xlPrevious, _
            MatchCase:=False _
        )
    If _
        rngResults Is Nothing _
        Then
        GetLastUsedRowNumberInWorksheet = _
            -1
    Else
        GetLastUsedRowNumberInWorksheet = _
            rngResults.Row
    End If
    Exit Function
ErrorHandler:
    GetLastUsedRowNumberInWorksheet = _
        -1
End Function

Leave a Reply

Your email address will not be published.