+ Reply to Thread
Results 1 to 4 of 4

Count Number of Lines in Text File

  1. #1
    Registered User
    Join Date
    03-03-2005
    Posts
    20

    Question Count Number of Lines in Text File

    Hello,

    I have coded a macro that imports text file data and parses it into a worksheet. I have the macro count each line as data is imported and display the number imported on the status bar in the lower left corner of Excel. Right now, I have it set to say "### of records imported."

    I would like it to say "### of ### records imported" and then build a progress bar based upon this data. I do not know how to analyze a text file to obtain the number of lines it contains. Some of the text files I would import could be millions of lines, so it needs to be done quickly. Importing the text file alone can take several minutes.

    It is a minor detail, but if anyone knows how to do this without much trouble, please let me know.

    Thank you,

    NicB.

  2. #2
    Forum Contributor
    Join Date
    11-11-2005
    Posts
    267
    NicB,

    In the Do While Not EOF(#1) ... Loop, insert a conter as in n = n+1
    to monitor the number of lines imported.

    The downside to this is that it will take an eternity to go through the count if you are reckoning with lines in the millions!

    Myles

  3. #3
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388
    And it also means going through the text file twice, first to get the total number of records and again to import each one.

    It sounds like the text file is delimited in some way (you mention records). In that case it will be far quicker and easier to use ADO to read the file.
    I've found the following article very useful: http://msdn.microsoft.com/library/de...ng03092004.asp

  4. #4
    Registered User
    Join Date
    03-03-2005
    Posts
    20
    Thank you both for your thoughts. I am leaning towards ADO as well, just need to do some more reading on how it works. I will let you know if I get it to work successfully.

    NicB.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1