How to calculate Number of rows in Excel ?

A

anu

Hi ,
I have an excel sheet. i want to calculate the number of rows in the
excel sheet using Vb6.
This is the code that i have:

Dim S As String
Dim rlmt As Integer
Open CommonDialog1.FileName For Input As #1
rlmt = 0
' To get the number of rows
While Not EOF(1)
Line Input #1, S
rlmt = rlmt + 1
Wend
Close #1
MsgBox (rlmt)

this code seems to give me more no of rows than what is actually
there. Example, i had 7327 rows but my output using this code was
7330. Any help????

Thanks,
anu
 
D

dq

Anu,

The function you are using is only suited for textfiles. If you want
the number of rows in an excel sheet, use
Sheet1.UsedRange.Rows.Count() but remember that for excel every cell
with something in it or with (conditional) formatting is considered
used, so you might be counting some 'empty' rows.

DQ
 

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