Comments on: How to merge multiple Excel files into one

Merging multiple Excel workbooks into one file could be a cumbersome and long process. So, which is the best way to handle the problem: copy the sheet tabs, run VBA code or use a special tool? Continue reading

Comments page 2. Total comments: 249

  1. Hi, just want to say this is so helpful, thank you.

  2. Hi, I did use the macro above and it works just fine. However, it brings ALL the sheet from the workbooks across to the new workbook. How can I adjust the code to only bring One of the sheet from all the workbook? The sheet is called ABC in all of the workbooks.
    Thank you

    1. Hi! Copy this ABC sheet into a new workbook. Then copy this sheet from this new workbook to all other workbooks.

      1. Thanks Alexander. but let me rephrase my question.
        I need to copy one worksheet from multiple workbooks into multiple worksheets in one workbook. but I don't want ALL of the sheets within all of the workbooks to be copied across. Only a selected sheet.
        I also need to bring in the filename across, perhaps as a new column in the worksheet.
        would it be possible to adjust the VBA above to only pick one sheet name and also add the filename as a column?
        Many thanks

  3. Amazing! thank you so much. the VBA code works smoothly

  4. VBA script combines data in different sheets but I need to combine multiple workbook with single sheet data into single sheet. I wanted try to combine all sheets into through Data Query, do we have convert all the data sheets into tables. Do we have any short cut for converting multple data sheets into tables.

  5. I have problems pressing ALT + F8 not working. FN + ALT F8 also not working

  6. That macro is amazing! I was even able to pull them off my OneDrive. Thank you so much!

  7. This Excel macro helped my greatly, thank you so much to the author!

  8. Hello when I run the macro only the first 2 files appear for me to select. There is a total of 6 files. Is this due to the size of the files and if so is there a way to fix it?

    Thank you!!

  9. Struggling with the fact that the sheets produced by this are not the original filenames. Is there a modification to the VBA macro code that I could make which would make the name of the sheet into the name of the file (minus the file extension)?

  10. I need to combine multiple files, and I need all to combine I seperate sheets.

  11. VBA script combines data in different sheets but I need to combine multiple workbook with single sheet data into single sheet. VBA script?

    1. YOu might want to consider PowerQuery for this

  12. Hello,

    Is there any way to get data from specific cells from multiple spreadsheets and consolidate them in one spreadsheet?

    This is the situation: I want to consolidate 150 spreadsheets into one and I want to get the data in cell B4 and Cell J10 of every spreadsheet.

    Thank you

  13. Hello!

    I have nine .xls files in a folder, I get the following error when running the code:
    Run-time error '1004'
    That name is already taken. Try a different one.

    Clicking on debug takes me to this line:
    wksCurSheet.Copy After:=wbkCurBook.Sheets(wbkCurBook.Sheets.Count)

    A few months ago the code used to work, now it is not.
    The code runs OK always until the 3rd file. I only have 2 sheets per file. The code merges the first 4 sheets, naming the first 2 without the (number) and the next 2 sheets as "Sheetname (2)" and "Sheet (2)". Then on the beginning of the 5th sheet the error happens.

    All files to be processed are closed when running the code.

    Please help if you have the time. Thanks for the code.

    1. I found the problem. The sheet names were all the same name and 27 characters long. I just renamed the sheets to something shorter and this macro worked.

  14. about to go crazy. how i can easily name worksheets' names with file names during mergin process? and how i can append this code part to the code below. please someone send me mail.

    respects.

  15. Change: <>
    To: <--this is what is causing the error

    Change: MsgBox "Procesed "
    to MsgBox "Processed " <-- this has not functional impact

    to end (before "End Sub") add
    Else
    MsgBox "No files selected", Title:="Merge Excel files"
    End If <-- this is to debug if you don't select file and it gives you a pop-up

    1. Ha, please note the the "& l t % g t" is automatically converted to less than and greater than.... so use the "" instead of the & that gets translated in the comment submission

      If (vbBoolean <> VarType(fnameList)) Then

      less than and greater than in this statement, use the actual characters.

  16. Hi,

    I'm getting a syntax error on the first if statement - sorry, not too familiar with VBA - any advice?

    1. Hi,

      I'm also getting a syntax error on the first if statement. I'm wondering if it could be from the settings.

      1. Hello!
        Try not to copy the VBA code from the article, but use the example file from the link at the end of the article.

  17. Hello- Thank you for making this script. Each of my tabs from different files are the same name, resulting in "File", then "File (2)" "File (3)". The space in the tab name is not acceptable by any formulas I am utilizing. How do I remove the space from the script?

    1. Hi Jeffrey,

      Try adding a line that renames the copied sheet. This could look something like this:

      ...
      wksCurSheet.Copy after:=wbkCurBook.Sheets(wbkCurBook.Sheets.Count)
      ActiveSheet.Name = "File" & countFiles
      ...

  18. For example if there's sales data for Fruits like Mango, Apple, Banana, Kiwi in four worksheets in a workbook named Sales_March and there are similar workbooks for rest of the months with same 4 worksheets. Now how do i combine the yearly sales data for Mango in one sheet, Apple in one sheet etc for all the four fruits in a new workbook? I have been trying to figure out a direct method for this but couldn't find anything yet.

    1. Hello!
      We have a ready-made solution for your task. I recommend paying attention to the tool Combine Sheets. You can merge data from multiple sheets and select columns to merge. It is available as a part of our Ultimate Suite for Excel that you can install in a trial mode and check how it works for free.

  19. How is it possible to merge two xcel spreadsheets keeping the columns that are in target and removing any rows from target that are no longer present in source.

    A b c d. ->. A b c.
    1. 1
    2. 3.
    3.

    Result

    A b c d
    1
    3

  20. I am trying to combine multiple excel sheets, however, I only need one tab from each sheet. The tab name is the same in all the sheets I am trying to combine. Is there a way to isolate and just pull the one tab from each excel sheet?

    1. Hello!
      I can recommend you a special tool for сopying selected worksheets from several workbooks to one file - Copy Sheets. You can combine all the sheets you need from different Excel files into one new workbook in a couple of clicks. It is available as a part of our Ultimate Suite for Excel that you can install in a trial mode and check how it works for free.

  21. I tried the macro and it looks like it combined all the files beautifully. However I have very random and numerous incidents where it changes the text formatting from 9 point to 18. There are too many to fix by hand. It happens on a cell and within a cell (only part of the text is resized larger). Microsoft 365 Apps for Enterprise V 2202.

  22. I am trying to merge spreadsheet B that has phone numbers, (total 175), on them, and match them to another spreadsheet A , that has 450 rows.
    SS B was returned to me by a company that provides phone numbers, but they could only provide 175 numbers out of the original 450 rows of data.
    Because I have more notes on Spreadsheet A, I would like to merge Spreadsheet B to SS A.
    How can I do this ??

  23. Hi Sir,

    I want to combine different excel files in a folder to one file in multiple sheets , i can do that but i have a challenge with excel files which i receive file name will be having date which changes so to combine all files without considering date i need to use prefix. Is there any solution where i can combine excel files from folder using prefix of file name . Example : Adverse_Events_26022022.xlsx and next time file name will be Adverse_Events_23032022.xlsx , if i take only Adverse_Events my macro will run. Could you please provide me solution.

    Thanks,
    Sujatha K

  24. Can this macro be modified to include CSV files?

    1. Hi,

      Adding *.csv; to the list in the line below allows you to select and merge .csv files.

      fnameList = Application.GetOpenFilename(FileFilter:="Microsoft Excel Workbooks (*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm", Title:="Choose Excel files to merge", MultiSelect:=True)

      Which becomes

      fnameList = Application.GetOpenFilename(FileFilter:="Microsoft Excel Workbooks (*.csv;*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm", Title:="Choose Excel files to merge", MultiSelect:=True)

      :)

  25. Thank you for the guidance.

    I went the VBA way and it worked as intended.

    Best Regards
    Ashish

  26. I have 3 Macros and I want to merge all 3 macros together to make 1 macro. Ive merged but now everytime I run 1 macro it opens the old file. How can I fix?

  27. What can I do to make this process automatically? I mean, whatever change you do in the other sheets you can see these changes reflected in the combined data without doing the all process again and not duplicating data. Thank you!

  28. Can you share how to modify the VBA code to only consolidate visible tabs from the target files?

  29. Hellow, how can I use macros if I want for example I have thirty people and they make transactions every week so if I click among of one person out of thirty people in Excell I want to bring me all his or her information concerning transactions that they made, so it is possible?

  30. You can use "Get Data" in the Data toolbar of Excel and import data from a folder, then choose combine and load. It's done quickly.

  31. More than 62 files, sheet name will not change to file name like sequence 1-62 of the first file.

  32. Would it be possible to only merge specific workbooks in a folder? I have a folder with multiple files and need to pair them up. So instead of creating multiple folders, I was thinking of a table where Workbook A would pair up with Workbook B, C with D? can this be achieved?

  33. How can I use this macro if I want to copy over just 1 of the 4 sheets in each workbook? I'm having trouble successfully referencing the single sheet. Also, how can we alter this to paste values?

  34. Instead of all the sheets in the file being combined, I just need a specific tab. I don't need all of the sheets in each file, I just need a specific tab. How can the VBA above be modified to help accomplish this?

    1. Hello!
      With the Copy Sheets tool, you can select multiple sheets and combine them in a workbook. Copy Sheets can also copy data from multiple sheets to one sheet. Read more here.

    2. Hi Jeremiah, I'm having this same issue, did you ever figure this out?

  35. I want to generate PDF files from an excel file. After this coding runs, the result is that I will have multiple PDF files with the suffix "-index.pdf" - (e.g., 875458-indexl.pdf) I can change the suffix to anything.

    And I will extract another set of PDF files from a zip file that have the identical file name as 875458.pdf.

    At the end, in one folder, there will be multiple pairs of files as below.

    875458.pdf
    875458-index.pdf
    875460.pdf
    875460-index.pdf
    954784.pdf
    954784-index.pdf
    My goal is to find a way to merge each pair of files into one file.

    The end result would be as below.

    875458.pdf
    875460.pdf
    954784.pdf

  36. thanks,it worked just fine

  37. Hello. Good day. Thanks for this. Would like to ask what could be added to this code to break the links of the files that you will merge? Because I'm getting #Value! in some cells that are linked to different sources. Thanks.

  38. Thanks for the macro. However, it changes colors such that original and output colors are different. Is there a fix? (I'm not knowledgeable in the whole macro code thing)

  39. your combine macro is the only one I could get to work for me.
    thanks

  40. I am trying to combine 31 different excel workbooks and all of them have a standard format and multiple sheets. However, they also have their macros too. When I merge them the macro is not producing the same answer in the combined workbook as it did previously and macros are all messed up now. Is there anyway I can combine all of them with their individual macros that dont get mixed up?

  41. We created a template with header and column names, we decided to split the task across workers, gave each of them the designed template with same column names. Each returned excel files with partly filled data (this I due to division of labour on our on end, reason why we created the template) since these files have the same row names and volume, we would like to merge the various files into one and have excel merge this files.
    Take for instance worker A works on the first 20 and B works on 21-40 or in no definite pattern, would excel be able to merge these files together? Please I need a solution, thanks

  42. Is there a way to print this without trying to copy as it? I need to do this but know I won't remember all this. Brain works better at 7am. And which is the easiest method? Thank you.

    1. Hi!
      If I understood the problem correctly, in order to print this article, you can use the key combination Ctrl + P

  43. If anyone else runs into an error saying "Method 'Copy' of object '_Worksheet' failed", it could be because you there are worksheets among your target files that are hidden.

    Adding the following line below BEFORE the copy would fix it, but bear in mind it will also unhide all hidden sheets

    wksCurSheet.Visible = xlSheetVisible
    wksCurSheet.Copy after:=wbkCurBook.Sheets(wbkCurBook.Sheets.Count)

  44. Script works perfectly however, I need them in a single sheet line under line.
    For more explanation
    I saved bulk data from outlook wish to have them in long date format (Date & Time). I would like to have them line by line

  45. Hello,

    How can I use the above code for specific sheets from various excels.

    Thank you

  46. How do you link columns in an excel file (say CAT.xlsx) to columns in another excel file(say DAT.xlsx) columns using macros?

  47. This worked great for me! is there a way I can add a column with the workbook name to each row so I can keep the data differentiated afterwards?

  48. Hi! I have 10 employees working on the same 5 tabs, each assigned there own rows. Will this work to merge all the information into one file??

    1. Hello!
      Unfortunately, without seeing your data it is difficult to give you any advice.
      You can try using Combine Sheets.
      It is available as a part of our Ultimate Suite for Excel that you can install in a trial mode and check how it works for free.
      If you have any other questions, please don’t hesitate to ask.

  49. Thanks for the script.

    This successfully merges the selected files in a single folder location. However, is there a way if the files to be merged are placed at different folder locations.

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)