Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default How to calculate Number of rows in Excel ?

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
dq dq is offline
external usenet poster
 
Posts: 46
Default How to calculate Number of rows in Excel ?

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How to calculate Number of rows in Excel ?

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" wrote in message
ups.com...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate number of rows and apply formula Grey Old Man[_2_] Excel Discussion (Misc queries) 4 March 15th 10 07:17 PM
Can you calculate the number of years between two dates in Excel 0 Christina Excel Worksheet Functions 4 December 4th 08 09:02 AM
How do I calculate the root of a number using Excel? Arthur Yeager Excel Worksheet Functions 4 May 10th 07 08:35 AM
How do I calculate number of Mondays in a given month in Excel? Rossta Excel Worksheet Functions 3 May 26th 06 04:07 PM
How to calculate number of month from 2008 in Excel? Frank[_25_] Excel Programming 4 February 8th 06 01:48 AM


All times are GMT +1. The time now is 09:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"