You are on page 1of 3

Sub combinedata()

Dim var As Integer

Dim sh As Worksheet

var = 0

For Each sh In Worksheets

If sh.Name = "Consolidated Data" Then

var = 1

Exit For

End If

Next sh

If var = 0 Then Sheets.Add(Before:=Sheets(1)).Name =


"Consolidated Data" Else

Sheets("Consolidated Data").Move Before:=Sheets(1)

Sheets(2).Activate

Sheets(2).Range(Range("a1"), Range("A1").End(xlToRight)).Copy

Sheets(1).Activate

Sheets("Consolidated Data").Paste Destination:=Range("a1")

For Each sh In Worksheets

If sh.Name <> ActiveSheet.Name Then

With sh

.Range("A2:N" & .Range("A" & Rows.Count).End(xlUp).Row).Copy _

Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1)

End With

End If
Next sh

ActiveWindow.DisplayGridlines = False

Range("A1").CurrentRegion.Select

Selection.Columns.AutoFit

End Sub
Follow the Steps

1. Copy this Code


2. Open the excel workbook where you want to consolidate data
3. Press the shortcut Alt + F11 to open the Visual Basic Window
4. In the Insert Menu, click on Module or use the shortcut Alt i m to add a Module.
Module is the place where the code is written
5. In the blank module paste the code and close the Visual Basic Editor
6. Then use the shortcut Alt + F8 to open the Macro Box. You would have the list
of all the macros here.
7. You would see the Macro that you have just pasted in the Module as
‘CombineData’.
8. Run it. Instantly a new sheet (consolidated data) will be inserted and the Macro
will automatically copy the data from the rest of the sheets
 

A few things to note

1. Be sure to enable macros before you start working with the code
2. This code is dynamic and can be used in your own workbook as well
3. The code will create a new sheet as Consolidated Data to consolidate the data.
If you already have that sheet in your workbook, the data will be consolidated
in that sheet
4. The blue and bold marked parts in the code can be changed to fit your data
range

Link:

https://www.goodly.co.in/consolidate-data-from-multiple-sheets/

You might also like