counting ranges of rows/cells


Posted by dave brown on June 22, 2001 11:23 AM

Hello,

I wonder if anyone can help me determine how I might be able to use VBA within excel to count the number of rows that contain data. I have played with this using this code:

Set owb = GetObject("Z:\dave's test folder\tester.xls")

owb.Activate

totalrows = Rows.Count

This returns all 65536 rows (essentially an empty sheet, right?)

Any suggestions?

Dave Brown
Hill AFB, Utah

Posted by Barrie Davidson on June 22, 2001 12:05 PM

totalrows = Rows.Count

You can try:
totalrows = Range("A65536").End(xlUp).Row

Of course, this assumes that the last record (row) contains data in column A.

Barrie



Posted by Dave Brown on June 25, 2001 11:14 AM

totalrows = Rows.Count

Thanks Barrie. Essentially, what I wanted to do was open the worksheet, parse through the rows, then passing back only the last 2 rows with data in them. I guess I need to loop through, and stop when the last row of data is read, then returning that row only as an object. Does that sound ok?

Dave