Consolidation macro

linesy

Board Regular
Joined
Sep 27, 2004
Messages
72
Hi all,

I'm looking for a macro that will create a new worksheet "consolidated" and copy and paste all of the data (excluding duplicating the headings - headings row 2) from each sheet into the consolidated worksheet unless the value in A1 is blank.

Any help is greatly appreciated.

Linesy
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Maybe this
TRY IT ON A COPY FIRST
Code:
Sub MM1()
Dim lr As Long, lr2 As Long, ws As Worksheet
Application.ScreenUpdating = False
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "Consolidated"
Sheets("Sheet1").Rows("2:2").Copy Destination:=Sheets("Consolidated").Rows("1:1")
lr2 = Sheets("Consolidated").Cells(Rows.Count, "A").End(xlUp).Row
For Each ws In Worksheets
    If ws.Name <> "Consolidated" Then
        ws.Activate
        If ws.Range("A1") <> "" Then
            lr = Cells(Rows.Count, "A").End(xlUp).Row
            Rows("3:" & lr).Copy Destination:=Sheets("Consolidated").Rows(lr2 + 1)
        End If
    End If
lr2 = Sheets("Consolidated").Cells(Rows.Count, "A").End(xlUp).Row
Next ws
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try this
Code:
Sub cons()
Dim sh As Worksheet, conSh As Worksheet, lr As Long, lc As Long
Set conSh = Sheets.Add(After:=Sheets(Sheets.Count))
conSh.Name = "Consolidated"
    For Each sh In ThisWorkbook.Sheets
        If sh.Range("A1") <> "" And sh.Name <> conSh.Name Then
            lr = sh.Cells.Find("*", sh.Range("A1"), xlFormulas, xlPart, xlByRows, xlPrevious).Row
            lc = sh.Cells.Find("*", sh.Range("A1"), xlFormulas, xlPart, xlByColumns, xlPrevious).Column
            If conSh.Range("A1") = "" Then sh.Range("A1", sh.Cells(2, lc)).Copy conSh.Range("A1")
            sh.Range("A3", sh.Cells(lr, lc)).Copy conSh.Cells(Rows.Count, 1).End(xlUp)(2)
        End If
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top