如何找到包含特定列中数据的最后一行?

如何找到包含特定列中数据的最后一行?

如何找到在特定列和特定工作表中包含数据的最后一行?



翻翻过去那场雪
浏览 592回答 3
3回答

PIPIONE

不如: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).RowEnd Function对于注释,这将返回最后一个单元格的行号,即使最后一行中只有一个单元格有数据:Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

摇曳的蔷薇

您应该使用.End(xlup)但是,与其使用65536,不如使用:sheetvar.Rows.Count这样,它就可以用于Excel 2007,我认为Excel 2007有超过65536行。

慕运维8079593

function LastRowIndex(byval w as worksheet, byval col as variant) as long   dim r as range  set r = application.intersect(w.usedrange, w.columns(col))   if not r is nothing then     set r = r.cells(r.cells.count)     if isempty(r.value) then       LastRowIndex = r.end(xlup).row    else       LastRowIndex = r.row    end if   end ifend function用法:? LastRowIndex(ActiveSheet, 5)? LastRowIndex(ActiveSheet, "AI")
打开App,查看更多内容
随时随地看视频慕课网APP