+ Reply to Thread
Results 1 to 12 of 12

Merge multiple files into one file

  1. #1
    Forum Contributor
    Join Date
    08-05-2022
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    103

    Merge multiple files into one file

    Hi. I have had a look online and in this forum and cannot find exactly what I am looking for.

    On monthly basis I have 20 XLS files. I have to merge them all manually into one XLS file/workbook (all together on one sheet).

    Is there any VBA code which can do this and also remove any blank lines from the final output. The folder each month will change, so I will just place a blank worksheet with the macro in the current folder with the 20 files each month.

    Many thanks in advance.

  2. #2
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,505

    Re: Merge multiple files into one file

    I can give you a VBA solution but it is easier/more reliable and faster with Power Query. Ever heard of that?

  3. #3
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,505

    Re: Merge multiple files into one file

    If the setup of the files are identical you can try to run this macro in an empty sheet (make sure there is something in cell A1 before you run it. A header or something).
    It will ask for a folder. Just pick the folder where your files are located.

    Please Login or Register  to view this content.
    Last edited by JEC.; 08-17-2022 at 11:01 AM.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,791

    Re: Merge multiple files into one file

    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Forum Contributor
    Join Date
    08-05-2022
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    103

    Re: Merge multiple files into one file

    Quote Originally Posted by JEC. View Post
    I can give you a VBA solution but it is easier/more reliable and faster with Power Query. Ever heard of that?
    Hi. I have used power query importing one single file and doing some transformations. I didn't know that you could do multiple files at once with power query. I had a look into it then another user posted the video below which helped. that seems to work.

    In regards to the code below, I put it in a blank xlsm file except for headers as you stated and saved the macro but it didn't seem to do anything. It ran, but no changes to the file.

  6. #6
    Forum Contributor
    Join Date
    08-05-2022
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    103

    Re: Merge multiple files into one file

    Quote Originally Posted by alansidman View Post
    Many thanks. I have used power query before but not much. I have imported single files and transformed data a little. I didnt know you could use multiple files and import at once into one file. that worked for me. something new for me. thanks

  7. #7
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,505

    Re: Merge multiple files into one file

    Well, the code works fine here. I made small change after I posted it. You could try it again.

  8. #8
    Forum Contributor
    Join Date
    08-05-2022
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    103

    Re: Merge multiple files into one file

    Quote Originally Posted by JEC. View Post
    Well, the code works fine here. I made small change after I posted it. You could try it again.
    Hi. I picked up the amended code and started again. First it didn't work, but I realised that all my files are .XLS. So, I changed one file to .xls and it worked. So, I changed "If it Like "*xls*" Then" to "If it Like "*XLS*" Then" and it all worked. unfortunately, the system the files are extracted from name the files automatically with .XLS extension.

    Its really fast your script so that's great. Thanks for your help.

    Regards

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,791

    Re: Merge multiple files into one file

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  10. #10
    Forum Contributor
    Join Date
    08-05-2022
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    103

    Re: Merge multiple files into one file

    Quote Originally Posted by JEC. View Post
    Well, the code works fine here. I made small change after I posted it. You could try it again.
    Hi. Could you possibly change the code so that I can test if cell A in each row is blank or has the word total in it and if so delete the entire row in both cases?

    Thanks in advance.

  11. #11
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,505

    Re: Merge multiple files into one file

    Yes sure:

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    08-05-2022
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    103

    Re: Merge multiple files into one file

    Quote Originally Posted by JEC. View Post
    Yes sure:

    Please Login or Register  to view this content.
    Many thanks. perfect

+ 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. Merge multiple csv files with the same file name into one csv
    By chocoprince in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-04-2020, 07:28 PM
  2. [SOLVED] Macro to merge multiple excel files with same tab name into one file
    By Ardiko in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-16-2013, 04:53 PM
  3. [SOLVED] How to merge multiple excel files(xls) in one folder into a new xls file.
    By Hayk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2013, 11:48 AM
  4. [SOLVED] How to merge multiple xlsm files into a single file
    By gmatoka in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-18-2012, 07:52 AM
  5. merge specific cell from multiple files into 1 file
    By pow828 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-18-2011, 12:35 PM
  6. How to merge multiple Excel Files into One File
    By janeshh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2009, 08:09 AM
  7. How do I merge multiple xls files into one file?
    By Gianni in forum Excel General
    Replies: 3
    Last Post: 06-14-2005, 10:05 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