Services

Start a project
Excel

Combine multiple sheets into one in Excel.

One tab per month, store or rep, and now you need it all in one table. Here are three ways to do it, from a one-line formula to a macro you can run with one click, and how to pick.

Which one should you use?

MethodBest forNeeds
VSTACK formulaA few tabs, and a result that updates liveExcel 365 or 2024
Power QueryLots of data you refresh regularlyExcel 2016 or newer on Windows (more limited on a Mac)
VBA macroOne-click runs, a column showing which tab each row came from, any tab namesA macro-enabled file (.xlsm)

All three work best when every tab has the same columns in the same order. Check that first, because it’s the usual cause of a messy result.

Way 1: The VSTACK formula

On a new tab, this stacks the rows from every sheet between Jan and Dec in your tab order. It starts at row 2 to leave out the headers:

=VSTACK(Jan:Dec!A2:D1000)

Empty rows come through as zeros. To drop them, wrap it in FILTER, keeping rows where column A isn’t empty:

=LET(data, VSTACK(Jan:Dec!A2:D1000),
     FILTER(data, INDEX(data, , 1) <> 0))

Type your headers in row 1 and put the formula in A2. It updates by itself when the tabs change.

Way 2: Power Query

  1. Turn each tab’s data into a table: click in the data and press Ctrl+T (Cmd+T on a Mac).
  2. For each table, choose Data → From Table/Range, then Close & Load To… → Only Create Connection.
  3. Choose Data → Get Data → Combine Queries → Append, pick Three or more tables and add them all.
  4. Click Close & Load. To update it later, use Data → Refresh All.

Way 3: A VBA macro

This builds a new Combined tab with one header row and a Source column showing which tab each row came from. Press Alt+F11 (on a Mac, Tools → Macro → Visual Basic Editor), choose Insert → Module and paste it in:

Option Explicit

Sub CombineSheets()
    Const MASTER_NAME As String = "Combined"
    Dim wb As Workbook, ws As Worksheet, master As Worksheet
    Dim lastRow As Long, lastCol As Long, nextRow As Long
    Dim firstRow As Long, rowCount As Long, headerDone As Boolean

    Set wb = ActiveWorkbook

    On Error Resume Next
    Set master = wb.Worksheets(MASTER_NAME)
    On Error GoTo 0

    If Not master Is Nothing Then
        If MsgBox("Replace the existing " & MASTER_NAME & " tab?", _
                  vbYesNo + vbQuestion) <> vbYes Then Exit Sub
        master.Cells.Clear
    Else
        Set master = wb.Worksheets.Add(Before:=wb.Worksheets(1))
        master.Name = MASTER_NAME
    End If

    Application.ScreenUpdating = False
    nextRow = 1

    For Each ws In wb.Worksheets
        If ws.Name <> MASTER_NAME And Application.WorksheetFunction.CountA(ws.Cells) > 0 Then
            lastRow = ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            lastCol = ws.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column

            If Not headerDone Then
                master.Cells(1, 1).Value = "Source"
                master.Cells(1, 2).Resize(1, lastCol).Value = ws.Cells(1, 1).Resize(1, lastCol).Value
                master.Rows(1).Font.Bold = True
                headerDone = True
                nextRow = 2
            End If

            firstRow = 2
            rowCount = lastRow - firstRow + 1
            If rowCount > 0 Then
                master.Cells(nextRow, 1).Resize(rowCount, 1).Value = ws.Name
                master.Cells(nextRow, 2).Resize(rowCount, lastCol).Value = _
                    ws.Cells(firstRow, 1).Resize(rowCount, lastCol).Value
                nextRow = nextRow + rowCount
            End If
        End If
    Next ws

    master.Columns.AutoFit
    Application.ScreenUpdating = True
    MsgBox "Combined " & Application.Max(nextRow - 2, 0) & " rows.", vbInformation
End Sub

Save the file as .xlsm. To run it, press Alt+F8 (Tools → Macro → Macros on a Mac), pick CombineSheets and click Run. Try it on a copy first, because a macro’s changes can’t be undone with Ctrl+Z.

The macro copies values, so number and date formats may need setting again on the new tab, and it reads the header from the first tab with data. Hidden tabs are included too.

Common problems

  • Columns don’t line up: one tab has a different column order. Fix that tab, or use Power Query, which matches columns by name.
  • A summary tab got included: move it outside the Jan:Dec range for the formula, or add its name to the If line in the macro.
  • Dates turn into numbers: select the column and format it as a date.

Merging many files, not just tabs?

I build Excel macros that merge whole folders of workbooks, clean the data and make the report, with one button. Clean, commented code you own, tested on a copy of your file.