0

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

If I have a spreadsheet and the largest row number which has data is 10,434 is there a function which will give me the row number 10,434?

Thank you

Community
  • 1
  • 1
intrigued_66
  • 16,082
  • 51
  • 118
  • 189

1 Answers1

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

(will work as long as you have less than 65536 rows)

brettdj
  • 54,857
  • 16
  • 114
  • 177
Nullbeans
  • 309
  • 1
  • 8
  • This code uses the 65536 row limit of xl2003. A more robust version is `Cells(Rows.Count, col)`. But this still fails in this example for a blank column – brettdj Jul 04 '12 at 14:19