Merging worksheets

Heydiddle

New Member
Joined
Apr 8, 2013
Messages
8
I have many worksheets (same headings) that I want to consolidate into one workbook. What I've read so far is not helping I was hoping someone on here can help me.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Here is a generic copy and paste that should get it all into one book. After that you can sort and shuffle to organize the data. Since it has the same headings, one sheet's data will just be copied beneath the prior sheet.
This code assumes row 1 as a header row in Each worksheet. It will add a new sheet, then copy the contents of each existing sheet in the workbook to the new sheet, consecutively in the order of the name tabs at the bottom of the pane. It will then ask for a file name and when the file name is provided, if there are no errors, it will save the file as an file. If you attempt to save it as other than an xl file, it could error because no fileformat code is provided. You should end up with the original workbook intact and a new consolidated single sheet workbook.
Code:
Sub cons()
Dim sh As Worksheet, lr As Long, lc As Long, newSh As Worksheet
Set newSh = Sheets.Add After:=Sheets(ThisWorkbook.Sheets.Count)
ThisWorkbook.Sheets(1).Rows(1).Copy newSheet.Range("A1")
    For Each sh In ThisWorkbook.Sheets
        lc = sh.Cells.Find(What:="*", After:=sh.Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, _
            SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False).Column
        lr = sh.Cells.Find(What:="*", After:=sh.Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, _
            SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
        With sh
            If sh.Name <> newSh.Name Then
                .Range(.Cells(2, 1), .Cells(lr, lc)).Copy newSh.Cells(Rows.Count, 1).End(xlUp)(2)
            End If
        End With
    Next
    newSh.Copy
    fName = InputBox("Enter a file name and file with file extension.  Example: Consolidated.xlsx", "File Name")
        ActiveWorkbook.SaveAs fName
End Sub

This also assumed that all of the original sheets were in the same workbook.
 
Upvote 0

Forum statistics

Threads
1,203,457
Messages
6,055,546
Members
444,795
Latest member
cjohnson333

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