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

10
  • That question doesn't look related- unless i am after usedrange? Commented Jul 4, 2012 at 13:57
  • Are you looking for the last row which has data? Commented Jul 4, 2012 at 13:58
  • @Remou: That is an incorrect way of finding the lastrow. Commented Jul 4, 2012 at 14:09
  • The duplicate posted is also a duplicate and therefore an incorrect reference. Commented Jul 4, 2012 at 14:12
  • 1
    @Porcupine: Did you see my answer in the link that I gave? That will work in any version of Excel Commented Jul 4, 2012 at 14:27

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.