How to merge multiple Excel files into one file

bardimin pic

Written by Bardimin

On February 25, 2022
Home » Blogs » Software » How to merge multiple Excel files into one file

Do you have many Excel files and want to merge them into one?

Maybe you want to merge several daily reports into one monthly report file. Or you want to merge sales reports for each area into one report file.

There are many ways to merge multiple Excel files into one file. If the files that you want to merge are few, you can do it manually. You can do this by “Copy & Paste” the contents of the document, “Move or Copy” sheets, and so on.

If you are going to merge many files, the fastest way is to use VBA Macros.

Merge multiple Excel files into one

  1. Create a new file.
  2. Press ( Alt + F11 ) to open the Editor.
  3. After the Editor window opens, then click “ ThisWorkbook > Insert > Module ”.
unprotect-sheet-excel-01
  1. Then copy the following
Sub MergeExcelFiles()
    Dim fnameList, fnameCurFile As Variant
    Dim countFiles, countSheets As Integer
    Dim wksCurSheet As Worksheet
    Dim wbkCurBook, wbkSrcBook As Workbook
 
    fnameList = Application.GetOpenFilename(FileFilter:="Microsoft Excel Workbooks (*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm", Title:="Choose Excel files to merge", MultiSelect:=True)
 
    If (vbBoolean <> VarType(fnameList)) Then
 
        If (UBound(fnameList) > 0) Then
            countFiles = 0
            countSheets = 0
 
            Application.ScreenUpdating = False
            Application.Calculation = xlCalculationManual
 
            Set wbkCurBook = ActiveWorkbook
 
            For Each fnameCurFile In fnameList
                countFiles = countFiles + 1
 
                Set wbkSrcBook = Workbooks.Open(Filename:=fnameCurFile)
 
                For Each wksCurSheet In wbkSrcBook.Sheets
                    countSheets = countSheets + 1
                    wksCurSheet.Copy after:=wbkCurBook.Sheets(wbkCurBook.Sheets.Count)
                Next
 
                wbkSrcBook.Close SaveChanges:=False
 
            Next
 
            Application.ScreenUpdating = True
            Application.Calculation = xlCalculationAutomatic
 
            MsgBox "Processed " & countFiles & " files" & vbCrLf & "Merged " & countSheets & " worksheets", Title:="Merge Excel files"
        End If
 
    Else
        MsgBox "No files selected", Title:="Merge Excel files"
    End If
End Sub

Source: ablebits.com

  1. Then click the “ Run ” button to merge.
merger-excel-file
  1. Next, select the files you want to merge. Then click “Open“.
excel-dialog
  1. Wait for the process to finish.
merger-excel-end

Latest Articles

How to Restrict Data Input in Excel – Allow Only Certain Values

How to Restrict Data Input in Excel – Allow Only Certain Values

In Excel, you can restrict users by only allowing data input with the values you have specified. In this article, Bardimin will share some tricks to only allow the input of specific values in Excel cells. Data entry errors are a problem for any Excel user who wants...

How to Sum Number Columns and Rows in a Microsoft Word Table

How to Sum Number Columns and Rows in a Microsoft Word Table

Microsoft Word is known as a popular program for editing documents, but did you know that you can also perform calculations in Word? One of the biggest challenges faced during the manual data entry process is the possibility of errors in performing numerical...

Redirect and Block URLs with HOSTS File on Windows

Redirect and Block URLs with HOSTS File on Windows

Redirect and Block URLs you can easily on Windows. Just by adding the IP of a website, you can redirect or block it. Of course, this is very useful to limit the access of your employees or children from accessing websites that you do not allow. Your Windows PC has...

Repeating and Keeping Table Headings on Each Page in Microsoft Word

Repeating and Keeping Table Headings on Each Page in Microsoft Word

Using tables is one efficient and organized way to display data in rows and columns. Good table formatting will make the table visually appealing. If you often work with Microsoft Word documents, chances are you need to periodically use tables when recording data. In...

How to Bypass Forgotten BIOS Password

How to Bypass Forgotten BIOS Password

If you have created a BIOS password for your PC/Laptop and forgot it, you may have to send it back to the manufacturer. Don't worry, there are still several methods you can use to bypass or unlock the BIOS password. The BIOS password serves as a form of authentication...