Solved

merge multiple worksheets into a single master worksheet

Posted on 2014-01-16
4
1,166 Views
Last Modified: 2014-01-16
Dear Experts:

below code merges all of the worksheets of the currently active Workbook into a master worksheet named 'Combined'.

Could somebody help me tweak this code with the following requirements.

1.
All of the worksheets to be copied into the 'combined worksheets' have a column header that spans three rows (therefore the '.Offset(3, 0)' in line 15). The Combined Sheet should have this column header at the very top, i.e a column header that spans three rows. With the current code it is just a one row column header.

2.
All of the sheets are to be combined in this master worksheet named 'Combined' with the exception of sheets named 'Evaluation', 'Evaluation Master' and 'Result'

3.
The selected rows/cells in all of the sheets are to be deselected.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Sub Merge_multiple_worksheets()
'Merging multiple worksheets into a master worksheet
Dim J As Integer
On Error Resume Next
Sheets(1).Select
Worksheets.Add
Sheets(1).Name = "Combined"
Sheets(2).Activate
Range("A1:A3").EntireRow.Select
Selection.Copy Destination:=Sheets(1).Range("A1")
For J = 2 To Sheets.Count
Sheets(J).Activate
Range("A1").Select
Selection.CurrentRegion.Select
Selection.Offset(3, 0).Resize(Selection.Rows.Count - 1).Select
Selection.Copy Destination:=Sheets(1).Range("A65536").End(xlUp)(2)
Next
End Sub

Open in new window

0
Comment
Question by:AndreasHermle
  • 2
4 Comments
 
LVL 29

Expert Comment

by:gowflow
ID: 39785575
Can you post the workbook ?
gowflow
0
 

Author Comment

by:AndreasHermle
ID: 39785613
Hi gowflow,

here we are. Thank you

Regards, Andreas

Worksheet-Combining.xlsm
0
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39785655
Hi,

pls try

Sub Merge_multiple_worksheets()
'Merging multiple worksheets into a master worksheet
Dim J As Integer
On Error Resume Next
Sheets(1).Select
Worksheets.Add
Sheets(1).Name = "Combined"
Sheets(2).Activate
Range("A1:A3").EntireRow.Copy Destination:=Sheets(1).Range("A1")
Sheets(1).Range("A3").Value = " "
Sheets(2).Columns("A:K").Copy
Sheets(1).Columns("A:K").PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
For J = 2 To Sheets.Count
    Sheets(J).Activate
    If ActiveSheet.Name = "Evaluation" Or _
        ActiveSheet.Name = "Evaluation_Master" Or ActiveSheet.Name = "Result" Then
    Else
        Set myRangeTmp = Range("A1").CurrentRegion
        Set myRange = myRangeTmp.Offset(3, 0).Resize(myRangeTmp.Rows.Count - 1)
        a = Sheets(1).Range("A65536").End(xlUp).Row
        myRange.Copy Destination:=Sheets(1).Range("A65536").End(xlUp)(2)
    End If
Next
Sheets(1).Activate
Range("A1").Select
End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:AndreasHermle
ID: 39786567
Hi Rgonzo,

this did the trick. Great, thank you very much for your great help.

Regards, Andreas
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now