How to Consolidate/Merge multiple worksheets into one master sheet using VBA?
Tags: toconsolidatemergemu, vbamacros
Published: 2021-09-14 02:31:59

---
title: How to Consolidate/Merge multiple worksheets into one master sheet using VBA?
published: true
date: 2021-09-13 04:50:48 UTC
tags: ToConsolidateMergeMu,VBAMacros
canonical_url: https://geekexcel.com/how-to-consolidate-merge-multiple-worksheets-into-one-master-sheet-using-vba/
---

In this tutorial, we will guide you on  **how to consolidate/merge multiple Worksheets into one master sheet using VBA**. Let’s get them below!! Get an official version of MS Excel from the following link: **[https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)**

## Example

- Firstly, in the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to **copy and paste** the following code.

```
Sub Merge_Sheets()

Dim startRow, startCol, lastRow, lastCol As Long
Dim headers As Range

'Set Master sheet for consolidation
Set mtr = Worksheets("Master")

Set wb = ThisWorkbook
'Get Headers
Set headers = Application.InputBox("Select the Headers", Type:=8)

'Copy Headers into master
headers.Copy mtr.Range("A1")
startRow = headers.Row + 1
startCol = headers.Column

Debug.Print startRow, startCol
'loop through all sheets
For Each ws In wb.Worksheets
     'except the master sheet from looping
     If ws.Name <> "Master" Then
        ws.Activate
        lastRow = Cells(Rows.Count, startCol).End(xlUp).Row
        lastCol = Cells(startRow, Columns.Count).End(xlToLeft).Column
        'get data from each worksheet and copy it into Master sheet
        Range(Cells(startRow, startCol), Cells(lastRow, lastCol)).Copy _
        mtr.Range("A" & mtr.Cells(Rows.Count, 1).End(xlUp).Row + 1)
           End If
Next ws

Worksheets("Master").Activate

End Sub

```

- After that, you need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Save-the-Code-27.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- You need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Now, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/09/Run-the-Code-14.png)<figcaption>Run the Code</figcaption>

- Finally, you will get  **output ** as given below in the Excel.

![](https://geekexcel.com/wp-content/uploads/2021/09/Output-3.png)<figcaption>Output</figcaption>

## Conclusion

Here, we have explained the step-by-step procedure on **how to consolidate/merge multiple Worksheets into one master sheet using VBA**. Make use of this. Please share your worthwhile  **feedback**  in the below  **comment**  section. To learn more, check out our website **[Geek Excel](https://geekexcel.com/)!!**

**Read Also:**

- **[How to Fill Cell References From Multiple Worksheets in Excel?](https://geekexcel.com/how-to-fill-cell-references-from-multiple-worksheets-in-excel/)**
- **[How to find Vlookup and Return the Matching Values from Multiple Worksheets?](https://geekexcel.com/how-to-find-vlookup-and-return-the-matching-values-from-multiple-worksheets/)**
- **[How to Delete All Hidden Worksheets with One Click in Excel 365?](https://geekexcel.com/how-to-delete-all-hidden-worksheets-with-one-click-in-excel-365/)**
- **[How to Show All Hidden Worksheets with One Click in Excel 365?](https://geekexcel.com/how-to-show-all-hidden-worksheets-with-one-click-in-excel-365/)**
- **[How to Delete All Blank or Empty Worksheets in Excel Office 365?](https://geekexcel.com/how-to-delete-all-blank-or-empty-worksheets-in-excel-office-365/)**