直到现在,要知道哪一行是数据的最后一行,我使用以下代码:
Function GetPrimeraFilaLibre(paramNombreHoja As String, paramColumnaReferencia As String)
GetPrimeraFilaLibre = Sheets(paramNombreHoja).Range(paramColumnaReferencia & "65536").End(xlUp).Offset(1, 0).Row
End Function
此函数将我想知道最后一行的工作表作为参数,并将我将检查它是否有数据的参考列作为第二个参数。
如果存在隐藏行,此功能不起作用的问题。我想知道最后一行的数据,不管它是否隐藏。
谢谢。
Range.Find
可用于返回最后一行,无论是否有隐藏行。
Function GetPrimeraFilaLibre(paramNombreHoja As String, paramColumnaReferencia As String) As Long
With Sheets(paramNombreHoja).Columns(paramColumnaReferencia)
GetPrimeraFilaLibre = .Find(What:="*", After:=.Cells(1, 1), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
End With
End Function
Function GetLastRow(SheetName As String, ColumnNameOrIndex As String) As Long
With Sheets(SheetName).Columns(ColumnNameOrIndex)
GetLastRow = .Find(What:="*", After:=.Cells(1, 1), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
End With
End Function
正如 VBasic2008 指出的那样,我们需要对处理MergedCells
.
Function GetLastRow(SheetName As String, ColumnNameOrIndex As String) As Long
Dim Target As Range
With Sheets(SheetName).Columns(ColumnNameOrIndex)
Set Target = .Find(What:="*", After:=.Cells(1, 1), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
End With
GetLastRow = Target.MergeArea.Rows.Count + Target.Row - 1
End Function
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句