+ Reply to Thread
Results 1 to 10 of 10

Merge data from all workbooks in folder based on first 3 characters of filename

  1. #1
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Merge data from all workbooks in folder based on first 3 characters of filename

    Hi

    I have taken the below code from someone else to merge the data from all workbooks in a folder:

    Please Login or Register  to view this content.
    This works fine but I have many files in the folder that have different names based on the first 3 characters (and with different dates), e.g file names are RAN02042016R, PAK01072016, ROS05042016, etc.

    How can I amend the above code to open each file where the first 3 letters are the same and copy to a new workbook each time?

    The end result in the example above would be to create 3 new workbooks and copy the data from all files with the names RAN, PAK and ROS respectively.

    Many thanks

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Merge data from all workbooks in folder based on first 3 characters of filename

    Try:

    Please Login or Register  to view this content.
    Last edited by millz; 08-04-2016 at 02:32 AM.
    多么想要告诉你 我好喜欢你

  3. #3
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Merge data from all workbooks in folder based on first 3 characters of filename

    Hi millz,

    thank you for that. How can I adjust it so that it opens each automatically and then proceeds with the macro? I have over 400 of these so ideally don't want to type each and run once.

  4. #4
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Merge data from all workbooks in folder based on first 3 characters of filename

    You have a UDF in this macro, so I can't test it without removing that part.

    Let me know how this goes.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Merge data from all workbooks in folder based on first 3 characters of filename

    Hi

    yes that works great, thank you

    However, all of the files end in "R", so I tried to amend this"

    Please Login or Register  to view this content.
    to this:

    Please Login or Register  to view this content.
    but it didn't work?

  6. #6
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Merge data from all workbooks in folder based on first 3 characters of filename

    If it's all ending with R, then you don't need to put it.

    You might want to add a newbook.Close below the SaveAs.

  7. #7
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Merge data from all workbooks in folder based on first 3 characters of filename

    sorry I should have been clearer.

    All the files that I need end in "R", there are files in the folder that do not end in "R".

  8. #8
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Merge data from all workbooks in folder based on first 3 characters of filename

    I only need the files that end in "R" in the directory, but I cannot get it to work. I also tried:


    Please Login or Register  to view this content.
    as the files all have the same number of characters but it didn't work?

  9. #9
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Merge data from all workbooks in folder based on first 3 characters of filename

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Merge data from all workbooks in folder based on first 3 characters of filename

    thank you, that is working fine

    However, is there a way it can copy the header data in the first one (the header data is all the same in all of the files I need to copy over).

+ 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. Replies: 1
    Last Post: 02-17-2016, 05:57 AM
  2. Merge multiple workbooks & move each merged worksheet into another folder
    By Dahlia in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-14-2016, 11:56 AM
  3. [SOLVED] Merge a range from all workbooks in a folder to one Master Sheet
    By ACALEX in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-02-2014, 11:05 AM
  4. Formula to return filename in folder based on partial filename
    By Rerock in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-26-2014, 12:28 PM
  5. VBA To set Filename based on 1st 10 characters of workbooks being consolidated
    By dawnmau in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-05-2014, 03:29 PM
  6. Merge workbooks in a folder and rename sheets to previous filenames
    By zej in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2013, 10:19 AM
  7. open all files in a folder with fixed number of characters in filename
    By Telemick in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 01-18-2012, 03:31 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