如何找到包含特定列中数据的最后一行?
问题描述:
如何找到特定列和特定工作表中包含数据的最后一行?
How can I find the last row that contains data in a specific column and on a specific sheet?
答
怎么样:
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