Results 1 to 7 of 7

Thread: How can I count how many rows inside a .csv file?

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    4

    How can I count how many rows inside a .csv file?

    Hello,

    I need help. How can I count how many rows inside a .csv file? Also is there a easy way to compare a .csv file and have it output the results to a file?

    Thanks!

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: How can I count how many rows inside a .csv file?

    You can achieve this by using a FileSystemObject object. Here's a sample function that will return the line count for a file. You will need to add areference to the Microsoft Scripting Runtime library in order for this to run.
    VB Code:
    1. Function Count_Lines(FilePath As String) As Long
    2. Dim fsoFile As Scripting.FileSystemObject
    3. Dim fsStream As Scripting.TextStream
    4.    
    5.     'Create a new File system Object
    6.     Set fsoFile = New Scripting.FileSystemObject
    7.    
    8.     'Open the file for reading
    9.     Set fsStream = fsoFile.OpenTextFile(Filename:=FilePath, IOMode:=ForReading)
    10.    
    11.     'Move to the bottom of the file
    12.     Do Until fsStream.AtEndOfStream
    13.         fsStream.SkipLine
    14.     Loop
    15.    
    16.     'Return the current line number,
    17.     'Which will equal the count as
    18.     'we are at the end of the file
    19.     Count_Lines = fsStream.Line
    20.    
    21.     'Clear Object Variables
    22.     Set fsStream = Nothing
    23.     Set fsoFile = Nothing
    24. End Function
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    4

    Re: How can I count how many rows inside a .csv file?

    Hey thanks for the reply. I'll see if this does the trick. 1 last question... how can I compare 2 excel files..? Do I compare row by row?
    Last edited by craigheartley; Apr 20th, 2006 at 06:37 AM.

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: How can I count how many rows inside a .csv file?

    That depends, what do you want to compare?
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    4

    Re: How can I count how many rows inside a .csv file?

    OK.

    Heres the deal... I dont have good VB and I'm trying to write a utility that takes 2 excel files (.CSV) and compare them to make sure they are the same. And then write the diffs out to a txt file as a report. Noone here has VB skills and I have very little... PLEASE HELP. Thanks!

  6. #6
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: How can I count how many rows inside a .csv file?

    Quote Originally Posted by craigheartley
    OK.

    Heres the deal... I dont have good VB and I'm trying to write a utility that takes 2 excel files (.CSV) and compare them to make sure they are the same. And then write the diffs out to a txt file as a report. Noone here has VB skills and I have very little... PLEASE HELP. Thanks!
    Since .csv is just a text file, one option is to read each file into byte arrays and then compare the bytes in a loop. Also, seems to me there used to be a DOS function to do binary compare of two files.............

  7. #7
    New Member
    Join Date
    Apr 2006
    Posts
    2

    Re: How can I count how many rows inside a .csv file?

    A DOS functgion wich is called FC
    Type help FC for more info

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width