+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    08-08-2008
    Location
    Johannesburg
    MS-Off Ver
    2007
    Posts
    54

    Macro to count rows in closed CSV files

    Hi All
    I have a folder 'ClientsData' that contains over 200 CSV files.
    Each file have an average of 21 rows of data. (some more..some less..)
    The data seats in column A only.


    I have (separate) an Excel file that contains the list of all the files that in 'ClientsData' folder.
    The file names are all in "A:A".

    I need a macro to check each file in the folder and
    store the number of rows that each file have, in Column B.

    Any suggestions of how to do that?

    Many thanks for your help
    Amit
    Last edited by furiousfox; 03-17-2010 at 06:59 AM.
    Using Excel 2007.
    Amit Cohen

  2. #2
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2003/2007
    Posts
    372

    Re: Macro to count rows in closed CSV files

    Start the macro recorder then Data > Get External Data > From Text and read one csv file.

    This creates a QueryTable object with a connection to the CSV file and you can use
    Code:
    QueryTable.ResultRange.Rows.Count
    to count the number of rows.

    Then it's just a matter of looping through each file on the sheet, changing the connection string.

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.2.0