+ Reply to Thread
Results 1 to 7 of 7

Reading data line from multiple txt files

  1. #1
    Registered User
    Join Date
    11-21-2011
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    3

    Question Reading data line from multiple txt files

    I have a folder containing 10 txt files. I would like to:

    access all 10 files
    loop through data lines of each file until a line starting with "Apples"
    write the entire "Apples" line in an Excel sheet

    Seems easy - unable to google an answer yet though - anyone more clever than me?
    Thank a lot / Doc

  2. #2
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Pendleton, OR
    MS-Off Ver
    Excel 2013
    Posts
    129

    Re: Reading data line from multiple txt files

    I do something similar in parsing GPS files. I read each line of each file in the folder and insert only the lines starting with $GPGGA. Here is my code (abbreviated). Hope it helps
    Please Login or Register  to view this content.
    I have not included the Browse function here, something I found somewhere, and you would have to start the rindex (row to write to) and change to "Apples" and your worksheet tab name.

  3. #3
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Pendleton, OR
    MS-Off Ver
    Excel 2013
    Posts
    129

    Re: Reading data line from multiple txt files

    By the way, this reads every file in the selected folder regardless of type or content. The Browse function is

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    11-21-2011
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Reading data line from multiple txt files

    Hi Johnny

    The folder is fixed so I don't need a prompt.

    When I run the modified code it will read from the first file, but then I get an error that the file is already open...? Any input on how to close the file before checking the next?

    Thanks/Doc

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,534

    Re: Reading data line from multiple txt files

    Quote Originally Posted by Dr. Schwartz View Post
    loop through data lines of each file until a line starting with "Apples"
    write the entire "Apples" line in an Excel sheet
    Try
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Pendleton, OR
    MS-Off Ver
    Excel 2013
    Posts
    129

    Re: Reading data line from multiple txt files

    Sorry. As I edited out my code I inadvertently left out the Close #1. You need that statement before you loop back to the next file.

  7. #7
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Pendleton, OR
    MS-Off Ver
    Excel 2013
    Posts
    129

    Re: Reading data line from multiple txt files

    For after your path is set
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Reading line by line data from Text file
    By wyldencl in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-18-2015, 10:09 PM
  2. Reading array of data line by line (stock tick data)
    By wyldencl in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-04-2015, 03:12 PM
  3. Formula for reading data out of several files
    By Rob7bb in forum Excel General
    Replies: 1
    Last Post: 05-07-2010, 06:12 AM
  4. Reading in multiple csv files from a list of filenames
    By TexAggie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2009, 09:13 PM
  5. Reading text files into excel with multiple spaces as delimiter
    By XLBob in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-06-2009, 10:05 AM
  6. Reading data from other files
    By Incoherent in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-02-2006, 04:00 AM
  7. Reading data from several files
    By DJ Dusty in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-12-2005, 04:13 PM

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