+ Reply to Thread
Results 1 to 5 of 5

Query multiple text files, one by one to put into rows

  1. #1
    Registered User
    Join Date
    12-13-2013
    Location
    N/A
    MS-Off Ver
    Excel 2010
    Posts
    5

    Query multiple text files, one by one to put into rows

    I have this macro already set up to choose one .txt file from a folder and then import the data. What I want is to set it up so I can select multiple .txt files and it will go through them one by one and perform the exact same thing on all of them. I just don't know how to set up an appropriate loop. Thanks!

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,293

    Re: Query multiple text files, one by one to put into rows

    This will build a table of values down the columns where batchID, etc are located. Use Ctrl-Click or Shift-Click to select multiple files

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    12-13-2013
    Location
    N/A
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Query multiple text files, one by one to put into rows

    Quote Originally Posted by Bernie Deitrick View Post
    This will build a table of values down the columns where batchID, etc are located. Use Ctrl-Click or Shift-Click to select multiple files

    Please Login or Register  to view this content.
    Almost there. This basically takes the first file and imports the data from only that file down a number of rows equal to the number of files I selected. But it doesn't seem to open any of the other files I select. I also forgot to mention originally that the ranges where these values are going already have offset built into to them so I don't need the offset in the VBA code.
    Last edited by twofooted; 09-12-2014 at 04:50 PM.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,293

    Re: Query multiple text files, one by one to put into rows

    Oops - forgot to clear out the old file stuff

    Add in text = ""

    So this:

    For i = iLB To UBound(myFile)
    Open myFile(i) For Input As #1

    Becomes this:

    For i = iLB To UBound(myFile)
    text = ""
    Open myFile(i) For Input As #1

  5. #5
    Registered User
    Join Date
    12-13-2013
    Location
    N/A
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Query multiple text files, one by one to put into rows

    Awesome! Thank you!

+ 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. Import multiple text files delete rows between lines with File Name
    By coronakyk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2014, 09:53 PM
  2. IMPORTING TEXT FILES TO EXCELL - Multiple Multi line text files
    By Toxicca in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-12-2014, 09:56 AM
  3. [SOLVED] Help with creating multiple text files from query result.
    By shere in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-09-2011, 02:46 PM
  4. using MS Query to import multiple text files
    By John99 in forum Excel General
    Replies: 1
    Last Post: 10-26-2009, 08:27 PM
  5. query multiple excel files
    By pollymoe in forum Excel General
    Replies: 1
    Last Post: 02-01-2006, 10:20 AM

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