Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic Classic (6 and earlier)
Expertise: Advanced
Jun 16, 2009

Get the Last Filled Row or Column in Any Excel Spreadsheet

Sometimes you need to know which is the last row or column in an Excel sheet that contains actual data. To do that, use the following code:

' Find last filled column in Excel sheet
i_col = XL_PlyWorksheet.cells(1, "A").End(xlToRight).Column

' Find last filled row in Excel sheet
i_row = XL_PlyWorksheet.Range("A65536").End(xlUp).Row

Don't forget to add a reference to Excel, or you'll get a compile-time error.

Pavana Shireesha
Thanks for your registration, follow us on our social networks to keep up-to-date