Master Sheet Macro Help

marvina2

New Member
Joined
Aug 4, 2014
Messages
7
Hello, first time posting here.

I've got this master sheet macro that used to work to merge all my tabs into one sheet for printing purposes, but now it gives me a "Run-time error '1004: We can't paste because the Copy are and paste area aren't the same size". It only started happening as I created a new tab/sheet.

Here's the macro;

Sub Merge()
Dim ws As Worksheet
ActiveSheet.UsedRange.Offset(0).Clear
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> ActiveSheet.Name And ws.Name <> Sheets("CSI List").Name And ws.Name <> Sheets("List").Name Then
ws.UsedRange.Offset(6).Copy
With Range("A65536").End(xlUp).Offset(1)
.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

End With
End If
Next
End Sub

Any help as to why this is happening would be greatly appreciated.
 
I do want to merge the data, but I also want the header cells to be merged (in order to understand what division the merged cells fall under). Because your macro is bringing in the header cells of the first sheet perfectly fine, is it not able to duplicate the process for all sheets?
 
Upvote 0
Give this a try:

Code:
Sub Merge()
    Dim ws As Worksheet
    Dim Master As Worksheet
    Dim Lastrow As Long
    Dim CopyRng As Range
    
    Set Master = Worksheets("Master")


    With Master
        Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
        .Range("A2:O" & Lastrow).Clear
    End With


    On Error GoTo myerror
    For Each ws In ActiveWorkbook.Worksheets




        Select Case ws.Name
        Case Master.Name, "CSI List", "List"
            'do nothing
        Case Else


            With ws
                Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
                If Lastrow < 11 Then GoTo nextsh
               Set CopyRng = .Range("A7:O" & Lastrow)
            End With


            With Master
                Lastrow = Master.Cells(Master.Rows.Count, "A").End(xlUp).Row + 1
                CopyRng.Copy
                With .Range("A" & Lastrow)
                    .PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
                                  False, Transpose:=False
                    .PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
                                  False, Transpose:=False




                End With
            End With
        End Select
nextsh:
        Application.CutCopyMode = False
        Set CopyRng = Nothing
    Next ws
myerror:
    If Err > 0 Then MsgBox (Error(Err)), 48, "Error"
End Sub

Dave
 
Upvote 0

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