我有这样的功能:
Function GetLastRowOnSheet(ByVal SheetName As Worksheet) As Long
On Error Resume Next
GetLastRowOnSheet = SheetName.Cells.Find(what:="*", after:=SheetName.Cells(1), searchorder:=xlByRows, searchdirection:=xlPrevious).Row
On Error GoTo 0
End Function
假设我有一个名为“Sheet1”的工作表,在我的 excel 工作表中,我希望能够说 =GetLastRowOnSheet('Sheet1')或使用命名范围
我可以使用上面的函数以及包含以下内容的子例程或函数在 vba 中轻松完成此操作:
Dim Sheet1 As Worksheet
Dim LastRow as Long
Set Sheet1 = ThisWorkbook.Sheets("Sheet1")
LastRow = GetLastRowOnSheet(Sheet1)
' last row then returns the last filled in cell on the sheet
想法?