+ Reply to Thread
Results 1 to 11 of 11

How to run Loop in VBA to import more than one file

  1. #1
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    How to run Loop in VBA to import more than one file

    Hello,

    I have recorded a macro which imports a text file. I have 5 such text files to import into the same sheet . Can anyone help modify the below code to loop through the text files in a folder and import them to a single sheet?

    Please Login or Register  to view this content.
    Thank you

  2. #2
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    Re: How to run Loop in VBA to import more than one file

    With my little knowledge i tried to use For Next but the each new text file is getting imported from cell A1 instead of from the previous lastrow.

    Please Login or Register  to view this content.
    Thank you

  3. #3
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    Re: How to run Loop in VBA to import more than one file

    Hello,

    I Tried even further

    Please Login or Register  to view this content.
    Thank you.
    Last edited by zaska; 03-26-2015 at 01:10 PM.

  4. #4
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: How to run Loop in VBA to import more than one file

    Cross Posted here:

    http://www.mrexcel.com/forum/excel-q...lications.html

    A message to forum cross posters.

    Please read this:
    http://www.excelguru.ca/node/7
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to run Loop in VBA to import more than one file

    Hi Zaska,

    This relies upon there being at least 5 text files:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  6. #6
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    Re: How to run Loop in VBA to import more than one file

    Sir,

    Thank you very much. Could you please modify few lines in the above code if i have to select multiple text files at once. OR read all the text files from a folder? I don't have clue on how to set Multiselect:=True..

    Please Login or Register  to view this content.
    Regards,
    zaska

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to run Loop in VBA to import more than one file

    HI Zaska,

    Thanks for the rep! - I'll see whether I can do more tomorrow

  8. #8
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    Re: How to run Loop in VBA to import more than one file

    Thank you sir.

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to run Loop in VBA to import more than one file

    Hi Zaska,

    The trick is to select the multiple files while you're depressing the control key

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    Re: How to run Loop in VBA to import more than one file

    Thank you Sir.

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to run Loop in VBA to import more than one file

    You're welcome!

+ 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. Macro - Open File Explorer, Select File, Import certain information from file
    By Drayde in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2015, 08:58 AM
  2. Replies: 1
    Last Post: 11-01-2013, 03:22 PM
  3. Import text file into Excel and using a loop to count unique words within the text
    By mrgriff21 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2013, 03:17 PM
  4. [SOLVED] Macro - Master file to import data from another open file with variable file name
    By jdodz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2012, 10:56 PM
  5. File import - select file and import sheet(1) from closed workbook
    By Armitage2k in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2011, 03:15 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