+ Reply to Thread
Results 1 to 7 of 7

Help with Macro to import multiple text files.

  1. #1
    Registered User
    Join Date
    05-22-2018
    Location
    England
    MS-Off Ver
    2010
    Posts
    3

    Help with Macro to import multiple text files.

    Good afternoon,

    I have the following macro which currently works to import text files from a specified folder to a new sheet in the current workbook and also separate it into columns based on CSV etc;

    Please Login or Register  to view this content.
    I have two questions;

    1 - Is it possible to only extract everything in the text file except the first two rows of text, as they are titles which are not needed?

    2 - How would I change the macro so that instead of importing it to a new sheet starting at A1, it will import to the current worksheet starting at D3 for example.

    I have attached an example text file of the ones I am trying to import.

    Many thanks in advance, from a VBA noob.
    Attached Files Attached Files

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Help with Macro to import multiple text files.

    This is the code that loads your source file into your consolidated file.
    Please Login or Register  to view this content.
    It pastes the copied ranges starting at B1, not A1. But, it then deletes column A after all the files are copied, making it appear that it loaded into A1 from the start. If you replace the lines above with the code below it should do what you want.
    Please Login or Register  to view this content.
    Last edited by JLGWhiz; 05-22-2018 at 02:43 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    05-22-2018
    Location
    England
    MS-Off Ver
    2010
    Posts
    3

    Re: Help with Macro to import multiple text files.

    Many thanks JLGWhiz!

    Now only one problem remains, which is how to only import everything from a text document except the first two lines!

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Help with Macro to import multiple text files.

    Quote Originally Posted by Enyavon View Post
    Many thanks JLGWhiz!

    Now only one problem remains, which is how to only import everything from a text document except the first two lines!
    Maybe I missed something. I thought the second code I posted did that. It only copies beginning on the third row of the used range. So if data starts on row 1 then the copy range starts from row 3.

    If you mean import from the text file to Excel then why not just delete the two rows after you import the data?
    Last edited by JLGWhiz; 05-23-2018 at 05:15 PM.

  5. #5
    Registered User
    Join Date
    05-22-2018
    Location
    England
    MS-Off Ver
    2010
    Posts
    3

    Re: Help with Macro to import multiple text files.

    Main reason is because I used this macro to import 30 odd different text files, each containing alot of lines of data (The example text file is what I import, but that x30), so having to scroll though all of those rows of data once its imported would take way too long and be too tedious. I do have a macro to merge the files if I manually convert the text files to excel files by importing the data, which allows me to set the range that is merged, but I was just wondering if a similar thing is possible with text files, as I essentially dont need the title lines, just the pure data.

  6. #6
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Help with Macro to import multiple text files.

    Quote Originally Posted by Enyavon View Post
    Main reason is because I used this macro to import 30 odd different text files, each containing alot of lines of data (The example text file is what I import, but that x30), so having to scroll though all of those rows of data once its imported would take way too long and be too tedious. I do have a macro to merge the files if I manually convert the text files to excel files by importing the data, which allows me to set the range that is merged, but I was just wondering if a similar thing is possible with text files, as I essentially dont need the title lines, just the pure data.
    I wasn't thinking of scrolling though all the files to do it. You can do it with code as you load it to Excel. Modify this line in your Demo macro as shown below.

    Please Login or Register  to view this content.
    See if that doesn't eliminate the first two rows. Or am I still missing the point somewhere. That is the only code I see that you said extracted data from a text file. If it is a .csv file then it should load into Excel automatically if opened as a workbook. Then you can use vba code just like any other workbook.
    Last edited by JLGWhiz; 05-23-2018 at 09:23 PM.

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

    Re: Help with Macro to import multiple text files.

    Try
    Please Login or Register  to view this content.
    Last edited by jindon; 05-23-2018 at 10:45 PM.

+ 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 into excel
    By bginsberg in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 11-20-2013, 04:05 PM
  2. Macro to import multiple text files into one excel (2007) sheet
    By schthi3 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-08-2013, 11:35 AM
  3. Replies: 0
    Last Post: 08-09-2013, 05:54 PM
  4. [SOLVED] Macro to Import Multiple TXT Files into workbook - User to select files/directory
    By saber007 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-15-2013, 08:43 PM
  5. Import multiple text files into 1 workbook
    By riddickisten in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-10-2013, 08:00 PM
  6. Macro to Parse Text - Import text to Excel from Multiple Text Files & Folders
    By Novice_To_Excel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-02-2012, 01:05 AM
  7. Macro to Import text for Multiple Files and arrange them in smiler way
    By mithil in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-04-2010, 12:56 PM
  8. Import of Multiple Text Files
    By yanks6rule in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2006, 07:34 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