+ Reply to Thread
Results 1 to 7 of 7

Import Multiple Text Files Into Single Worksheet

  1. #1
    Registered User
    Join Date
    12-22-2009
    Location
    San Francisco
    MS-Off Ver
    Excel 2007
    Posts
    31

    Arrow Import Multiple Text Files Into Single Worksheet

    Hi All,

    I have 150 .txt files that I'd like to import into a single worksheet.

    The .txt file is an article.

    Ideally, I'd love to have each .txt file imported like this:

    Title of article in Column A >>> Rest of article in Column B

    Is there a quick way to import these files (and hopefully separate the title/article)?

    Thanks so much!

    -Coz
    Attached Files Attached Files

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Import Multiple Text Files Into Single Worksheet

    What is the title of your article in your example ?



  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import Multiple Text Files Into Single Worksheet

    Hello cozandeffect,

    This macro will read all text files in a specified folder. The first line is assumed to be the title of the article. This will placed in "A1" on "Sheet1". You can change the starting cell and sheet name to what you are using. These appear in bold type. The remaining lines are placed in column "B".

    Copy Text Files to Worksheet
    Please Login or Register  to view this content.

    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time.
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    12-22-2009
    Location
    San Francisco
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Import Multiple Text Files Into Single Worksheet

    Leith,

    Thank you for your in-depth response.

    I notice the title shows up in Column A (excellent!) while the rest of the text shows up in multiple columns (instead of all in cell B1).

    Do you know how to move all the text into once cell only?

    I've attached the workbook with two sheets:

    Sheet #1 is what the macro creates
    Sheet #2 is what we need it to look like

    (Note: I copied the same article twice just for demonstration purposes)

    Again, thank you SO much for your help!

    Best,

    Coz
    Attached Files Attached Files

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import Multiple Text Files Into Single Worksheet

    Hello Coz,

    Here is the updated macro. The attached workbook has a button on "sheet1" to run the macro.

    Macro Code to Read Text Files
    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    12-22-2009
    Location
    San Francisco
    MS-Off Ver
    Excel 2007
    Posts
    31

    [SOLVED]Re: Import Multiple Text Files Into Single Worksheet

    Quote Originally Posted by Leith Ross View Post
    Hello Coz,

    Here is the updated macro. The attached workbook has a button on "sheet1" to run the macro.

    Macro Code to Read Text Files
    Please Login or Register  to view this content.
    Leith, you are a GOLDEN GOD!

    Thank you, thank you, thank you!

    Happy New Year!

    -Coz

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Import Multiple Text Files Into Single Worksheet

    Hello Coz,

    You're welcome and Happy New year!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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