How many rows are occupied by data: How to find that?

  • Thread starter Thread starter Jack
  • Start date Start date
J

Jack

Hello,
I am using Excel automation in my vbasic project.
I wonder whether there is a workbook (or worksheet) property returning
number of rows occupied by data.
If not, what will be the best method to find that number?
Jack
 
If your data starts in row 1, you could use

moExcelWS.usedRange.rows.count

If you're looking for the total number of used rows and the used range doesn't
start in row 1:

With moExcelWS.UsedRange
msgbox .rows(.rows.count).row
end with

(It'll work when the data starts in row 1, too.)

I liked to pick out a column that always has data in it to get that last row:

dim LastRow as long
with moExcelws
lastrow = .cells(.rows.count,"A").end(xlup).row
end with

(I used column A in this sample.)
 
Back
Top