PC Review


Reply
Thread Tools Rate Thread

How to calculate Number of rows in Excel ?

 
 
anu
Guest
Posts: n/a
 
      20th Apr 2007
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

 
Reply With Quote
 
 
 
 
dq
Guest
Posts: n/a
 
      20th Apr 2007
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

 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      23rd Apr 2007
Opening a binary Excel using these text file based tools will at best return
rubbish. The fact that the numbers are nearly equal is complete luck.
You can use automation from VB6, as DQ indicates:
http://support.microsoft.com/kb/219151

Or possibly ADO depending on the structure of the worksheet(s).
http://support.microsoft.com/kb/257819

NickHK


"anu" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate number of rows and apply formula Grey Old Man Microsoft Excel Misc 4 15th Mar 2010 07:17 PM
How do I calculate the root of a number using Excel? =?Utf-8?B?QXJ0aHVyIFllYWdlcg==?= Microsoft Excel Worksheet Functions 4 10th May 2007 08:35 AM
how to calculate with vba the number of records in an excel- table? André Microsoft Excel Misc 5 11th Nov 2006 01:30 PM
How to calculate fixed rows in Excel ( Sum of every 7 rows for i.. =?Utf-8?B?dG9ueXRhb2NoZXVuZw==?= Microsoft Excel Misc 7 12th Sep 2004 01:23 AM
Need to calculate the number of Filtered rows Paul Microsoft Excel Worksheet Functions 5 18th May 2004 02:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:38 PM.