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

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
 
D

Dave Peterson

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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top