Solved

merge multiple worksheets into a single master worksheet

Posted on 2014-01-16
4
1,202 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 49

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

772 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