Consolidate multiple worksheets into a new sheet

pkew22

New Member
Joined
Aug 30, 2013
Messages
38
In Excel 2013, I have a workbook where i want to combine multiple sheets into one worksheet. I have the same headers in each sheet.

I would like to create a sheet called Consolidate and merge the data from the other sheets into this sheet. I consolidate the sheets every three days. When I do, I delete the current Consolidate sheet and run this macro. Can someone show me how to check to see if there is a sheet called Consolidate and delete that sheet if it exists before running the rest of the macro?

Code:
Sub mcrConsolidate()
'Consolidate all Unit Dept Worksheets into the Consolidate Sheet


Dim wkShtNum As Integer
On Error Resume Next
'Select first worksheet and add Consolidate sheet to the left
Sheets(1).Select
Worksheets.Add
Sheets(1).Name = "Consolidate"
'Activate first Unit Dept Sheet and copy headings
    Sheets(2).Activate 'Activates second sheet as Consol is now first
    Range("A1:AC1").Copy 'Copy Headings
    Sheets("Consolidate").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False 'Paste col widths
        ActiveSheet.Paste  'Consolidate is now the activesheet
        Range("A1").Select
'Paste data in Consolidate


'Sheets("Consolidate").Range("A1").Paste Destination:=Sheets(1).Range("A1")


'Paste data from worksheet 2 to end to Consolidate
For wkShtNum = 2 To Sheets.Count
Sheets(wkShtNum).Activate
Range("A1").Select
Selection.CurrentRegion.Select
'Select everything but the header
Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
'Find first empty cell in Column A and Paste data
Selection.Copy Destination:=Sheets(1).Range("A6553").End(xlUp)(2)
Next
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I saw some code by Blade Hunter from a post from 2008. That helped a lot. I have amended this and am running two macros. One checks to see if the Consolidate sheet exists and deletes it and the other consolidates the sheets.

Code:
[COLOR=#222222][FONT=Verdana]Sub Consolidate()[/FONT][/COLOR]'Check to see if worksheet Consolidate exists and delete it if it does
'Consolidate Spreadsheet
        mcrDelConsolidate
        mcrConsolidate

End Sub


Private Sub DelConsolidate()
Dim wkSht As Worksheet
For Each wkSht In Worksheets
    If wkSht.Name = "Consolidate" Then
        Sheets("Consolidate").Delete
    End If
Next
End Sub


Private Sub mcrConsolidate()
'Consolidate all Unit Dept Worksheets into the Consolidate Sheet

Dim wkShtNum As Integer
On Error Resume Next
'Select first worksheet and add Consolidate sheet to the left
Sheets(1).Select
Worksheets.Add
Sheets(1).Name = "Consolidate"
'Activate first Unit Dept Sheet and copy headings
    Sheets(2).Activate 'Activates second sheet as Consol is now first
    Range("A1:AC1").Copy 'Copy Headings
    Sheets("Consolidate").Select
    
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False 'Paste col widths
        ActiveSheet.Paste  'Consolidate is now the activesheet
        Range("A1").Select
'Paste data in Consolidate


'Sheets("Consolidate").Range("A1").Paste Destination:=Sheets(1).Range("A1")


'Paste data from worksheet 2 to end to Consolidate
For wkShtNum = 2 To Sheets.Count
Sheets(wkShtNum).Activate
Range("A1").Select
Selection.CurrentRegion.Select
'Select everything but the header
Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
'Find first empty cell in Column A and Paste data
Selection.Copy Destination:=Sheets(1).Range("A6553").End(xlUp)(2)
Next
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,420
Messages
6,124,803
Members
449,190
Latest member
cindykay

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