当工作表中没有数据时
Find("*",,,,1,2).row会出错
所以我自定义了一个函数
代码语言:javascript复制Sub test()
With ActiveSheet
' On Error Resume Next,
a = .Cells.Find("*", , , , 1, 2).Row
b = getLastRow(ActiveSheet, 30)
Debug.Print b
' On Error GoTo 0
End With
End Sub
''' 输入工作表,空一维数组arr(1 to x),返回最大行数
Function getLastRow(sht As Worksheet, n As Integer)
Dim ti As Integer, tarr()
ReDim tarr(1 To n)
With sht
For ti = 1 To n
tarr(ti) = .Cells(Rows.Count, ti).End(xlUp).Row
Next ti
End With
getLastRow = Application.WorksheetFunction.Max(tarr)
End Function