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

后端 未结 13 1592
南笙
南笙 2020-11-22 03:44

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

13条回答
  •  鱼传尺愫
    2020-11-22 04:14

    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
    

提交回复
热议问题