+ Reply to Thread
Results 1 to 10 of 10

Import multiple text files into different sheets + delimiter

  1. #1
    Registered User
    Join Date
    08-23-2012
    Location
    Canada
    MS-Off Ver
    Excel 2017
    Posts
    25

    Import multiple text files into different sheets + delimiter

    Hey guys, first time posting here, absolutely no experience programming macros, but I did do some vba in high school about 5 years ago, so extremely rusty, let me explain my question.

    I have a text file for every month of the year for 4 years and I would like to import them to a single workbook but different sheets. I actually already found a solution to this, a section of code I found (from this forum I think?) I don't remember where I found it, so if the OP of this code could come forward and claim this, much appreciated.

    Also, I did hit the sticky but could not find the solution to my first problem, delimiters.
    I edited this code so it would ask for the path of the txt files as well as changed it from csv files to txt files.

    Please Login or Register  to view this content.
    Problem is, the text files have semicolon delimiters and I know that you set delimiter options in the "Workbooks.Open" command but I don't know the syntax.
    Also, I need 2 other things, first is a must have, but the second is not needed, it would just be nice.

    1) I need to add an extra column to each worksheet that adds certain cells together, eg B2 + C2 + E2, and implement this in the same code as the above.
    2) Copy these extra columns from each worksheet into a different workbook, specifying the start and end point for each set of 12 worksheets (Eg 2008 Jan - Dec in the 2008 worksheet, then 2009 Jan - Dec in the 2009 worksheet etc etc)

    Thanks a lot!! (Oh does Tapatalk work for this forum by the way?)
    Last edited by zijin_cheng; 08-23-2012 at 08:26 AM.

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Import multiple text files into different sheets + delimiter

    Try this

    Please Login or Register  to view this content.


    ---------- Post added at 08:56 AM ---------- Previous post was at 08:52 AM ----------

    How many columns are in your txt files?
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Registered User
    Join Date
    08-23-2012
    Location
    Canada
    MS-Off Ver
    Excel 2017
    Posts
    25

    Re: Import multiple text files into different sheets + delimiter

    Arrrrrrr, i did exactly that, but didnt know i had to put a colon! will try, thanks!

    there are 6 columns, 1 date, 1 time, 4 generator kWh columns, so 6 in total, will i need to add an array for 6 columns? thanks again

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Import multiple text files into different sheets + delimiter

    Ok, Here's another way of doing the same thing. Give a try. Change this part to your needs.

    Please Login or Register  to view this content.


    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-23-2012
    Location
    Canada
    MS-Off Ver
    Excel 2017
    Posts
    25

    Re: Import multiple text files into different sheets + delimiter

    Thanks!! Worked perfectly.

    I have also gotten each worksheet to add an additional column containing the sums of the respective rows, and now I'm trying to copy those columns into another sheet. The code I have currently works, however, it is copying the formulas, not the values. I then attempted to add the code in red, but was given a compile error: expected end of statement.

    Any help would be appreciated!!

    Please Login or Register  to view this content.
    Last edited by Cutter; 08-23-2012 at 07:29 PM. Reason: Removed whole post quote

  6. #6
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Import multiple text files into different sheets + delimiter

    what Columns are they? I cant really tell what your doing from your code.

  7. #7
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Import multiple text files into different sheets + delimiter

    Not sure exactly if this is what you want

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-23-2012
    Location
    Canada
    MS-Off Ver
    Excel 2017
    Posts
    25

    Re: Import multiple text files into different sheets + delimiter

    Sorry about that, this is the whole code, a little messy, haven't coded for a while.
    The red text wasn't there before, I added it to try and get the macro to paste special instead of pasting the formula there.

    I tried the last piece of code you posted but due to my lack of knowledge in VBA, there were a few probelms I didn't know how to resolve, such as "expect UBound to be an array"

    Please Login or Register  to view this content.

  9. #9
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Import multiple text files into different sheets + delimiter

    Thats what I thought you wanted to do. This will do it, Copy "H" EntireColumn from all worksheets Except the newly add worksheet. Starts in A1 then B1 ect...

    Please Login or Register  to view this content.

  10. #10
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Import multiple text files into different sheets + delimiter

    Give this a try

    Please Login or Register  to view this content.
    Last edited by mike7952; 08-24-2012 at 09:11 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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