获取包含数据的最低/最大行号的行号?

时间:2012-07-04 13:54:53

标签: excel vba

  

可能重复:
  How can I find last row that contains data in the excel sheet with a macro?
  Error Finding Last Used cell In VBA

如果我有一个电子表格,并且有数据的最大行号是10,434,那么有一个函数会给我行号10,434吗?

谢谢

1 个答案:

答案 0 :(得分:0)

Sub largestrow()
Dim largestrowNum As Long
Dim col As Integer
For col = 1 To Columns.Count
lastrow = Application.WorksheetFunction.Max(Cells(65536, col).End(xlUp).Row, largestrowNum)
Next col
MsgBox "Largest row number =" & largestrowNum
End Sub

(只要您的行数少于65536行即可使用)