How can I find last row that contains data in a specific column?

Lipis picture Lipis · Sep 16, 2008 · Viewed 354.7k times · Source

How can I find the last row that contains data in a specific column and on a specific sheet?

Answer

Fionnuala picture Fionnuala · Sep 16, 2008

How about:

Function GetLastRow(strSheet, strColumn) As Long
    Dim MyRange As Range

    Set MyRange = Worksheets(strSheet).Range(strColumn & "1")
    GetLastRow = Cells(Rows.Count, MyRange.Column).End(xlUp).Row
End Function

Regarding a comment, this will return the row number of the last cell even when only a single cell in the last row has data:

Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row