Excel VBA Combine all sheets into workbook into one sheet

Hi,

I'm trying to figure out a way to combine all my sheets into one sheet. Each sheet is completely different to each other (headings don't match etc...), so I don't want to consolidate the data.

I'm looking to combine the data into one sheet by pages, so I can then print each sheet on separate pages. For example I have 50 sheets - Question1, Question2, Question3, Question4 ... , Question50.

I would like to combine all of these into a 'Master' sheet. I want 'Question1' on page 1 of 'Master', then 'Question2' on page 2 of 'Master', then 'Question3' on page 3 of 'Master'. Once each sheet has been added to 'Master', I would like to delete it, then move onto the next sheet to be added.

I'm unsure on how to add each sheet as a separate page in 'Master'. 

Answer
Answer

Hi Abdullah MSL

Try this macro, I tested on my side and works OK

The macro will do the following

1- Create a new sheet and name it "Master"

2- Loop thru all the sheets in the workbook, transfer their data to the master sheet by creating a new page brake for each of them on Master sheet

3- Delete the transferred sheet

***************************************************************************

Sub CombineSheetswithPageBrakes()

Dim MasterSh As Worksheet

Dim QSh As Worksheet

Dim break As String


Application.ScreenUpdating = False

Application.DisplayAlerts = False


Set MasterSh = ThisWorkbook.Sheets.Add

MasterSh.Name = "Master"


For Each QSh In ThisWorkbook.Sheets

    If QSh.Name <> "Master" Then

            With MasterSh

            ''' Find the Page Break address

            break = .UsedRange.Offset(MasterSh.UsedRange.Rows.Count + 2).Resize(1, 1).Address

            '' Inserting the new page break

            .HPageBreaks.Add Before:=.Range(break)

           End With

           '' Copy/Paste (Transfer) the values form the other sheets to Master sheet

            QSh.UsedRange.Copy MasterSh.UsedRange.Offset(MasterSh.UsedRange.Rows.Count + 2).Resize(1, 1)

            '' Delete the sheet after transfer it to master sheet

            QSh.Delete

    End If

Next QSh

MasterSh.Rows("1:3").Delete


Application.ScreenUpdating = True

Application.DisplayAlerts = True


End Sub

******************************************************************************

Do let me know if you need more help

Regards

Jeovany

Please,
Consider marking this reply as the answer to your question if it does so.
It will help others in the community with similar problems or questions.
Thank you in advance


Regards
Jeovany CV

8 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated February 17, 2025 Views 12,971 Applies to: