Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting Rows with data in Excel/VB

Status
Not open for further replies.

solidjp

Programmer
Jul 16, 2002
29
US
I need to loop through all the rows in an Excel file that has data in each row. If I use Workbooks.Application.Rows.Count it returns every row (65235) or whatever. I usually just have around 100 or so rows with data in them. I'm using a For loop to do this. My code goes something like this...

For i = 1 to Workbooks.Application.Rows.Count 'Rows with data that doesn't work
.
.
.
Next

Thanks again in advance.
 
What are you doing within the loop? What are you testing to count?

You could test a known column for data
Code:
if(cell <> &quot;&quot;)then
  count = count + 1
end if
It's been a while since I've worked with the excel object. Can't remember what the exact line is for a cell value. Sorry. ---------------------------------------
Where would one begin to study Myology?
 
Rather than use Workbooks.Application.Rows.Count you might try using ExcelApp.ActiveWorkbook.Sheets(1).UsedRange.Rows.Count
where ExcelApp refers to your Excel Application Object. Also, if may need to adjust the (1) to the specific worksheet within that workbook that you're using. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top