Combine multiple sheets into summary

ryland00

Board Regular
Joined
Jun 13, 2014
Messages
76
Hello,

I am using the following code and it does not seem to be working. What it is supposed to be doing is taking everything from B12 through BY38 on all of the defined tabs below, and placing them on the summary sheet one after another. I feel like I am missing something relatively easy, but can't figure it out.

Any help would be appreciated.

Code:
Sub CopyRangeFromMultiWorksheetsNEW()
    Dim sh As Worksheet
    Dim DestSh As Worksheet
    Dim Last As Long
    Dim CopyRng As Range

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    'Set Dest to "Summary"
    Set DestSh = ActiveWorkbook.Sheets("Summary")

    'loop through all worksheets and copy the data to the DestSh
    For Each sh In ActiveWorkbook.Worksheets(Array("APAC", "AM", "EMEA", "INDIA", "LATAM", "CAN"))

            'Find the last row with data on the DestSh
            Last = DestSh.Cells.SpecialCells(xlCellTypeLastCell).Row

            'Fill in the range that you want to copy
            Set CopyRng = sh.Range("B12:BY38")

            'Test if there enough rows in the DestSh to copy all the data
            If Last + CopyRng.Rows.Count > DestSh.Rows.Count Then
                MsgBox "There are not enough rows in the Destsh"
                GoTo ExitTheSub
            End If

            'This example copies values/formats, if you only want to copy the
            'values or want to copy everything look at the example below this macro
            CopyRng.Copy
            With DestSh.Cells(Last + 1, "A")
                .PasteSpecial xlPasteValues
                .PasteSpecial xlPasteFormats
                Application.CutCopyMode = False
            End With

    Next

ExitTheSub:

    Application.Goto DestSh.Cells(1)

    'AutoFit the column width in the DestSh sheet
    DestSh.Columns.AutoFit

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With

End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I'd suggest changing
Code:
 Last = DestSh.Cells.SpecialCells(xlCellTypeLastCell).Row
to
Code:
 Last = DestSh.Range("B" & Rows.Count).End(xlUp).Row
As the xlCellTypeLastCell is somewhat flaky.
Other than that what is not working?
 
Upvote 0
Try:
Code:
Sub CopyRangeFromMultiWorksheetsNEW()
    Dim sh As Worksheet
    Dim DestSh As Worksheet
    Dim Last As Long
    Dim CopyRng As Range
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    Set DestSh = ActiveWorkbook.Sheets("Summary")
    For Each sh In Sheets(Array("APAC", "AM", "EMEA", "INDIA", "LATAM", "CAN"))
        Last = DestSh.Range("A" & Rows.Count).End(xlUp).Row
        If Last + 27 > DestSh.Rows.Count Then
            MsgBox "There are not enough rows in the Destsh"
            GoTo ExitTheSub
        End If
        sh.Range("B12:BY38").Copy
        With DestSh.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
            .PasteSpecial xlPasteValues
            .PasteSpecial xlPasteFormats
            Application.CutCopyMode = False
        End With
    Next sh
ExitTheSub:
    Application.Goto DestSh.Cells(1)
    DestSh.Columns.AutoFit
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub
 
Upvote 0
Try:
Code:
Sub CopyRangeFromMultiWorksheetsNEW()
    Dim sh As Worksheet
    Dim DestSh As Worksheet
    Dim Last As Long
    Dim CopyRng As Range
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    Set DestSh = ActiveWorkbook.Sheets("Summary")
    For Each sh In Sheets(Array("APAC", "AM", "EMEA", "INDIA", "LATAM", "CAN"))
        Last = DestSh.Range("A" & Rows.Count).End(xlUp).Row
        If Last + 27 > DestSh.Rows.Count Then
            MsgBox "There are not enough rows in the Destsh"
            GoTo ExitTheSub
        End If
        sh.Range("B12:BY38").Copy
        With DestSh.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
            .PasteSpecial xlPasteValues
            .PasteSpecial xlPasteFormats
            Application.CutCopyMode = False
        End With
    Next sh
ExitTheSub:
    Application.Goto DestSh.Cells(1)
    DestSh.Columns.AutoFit
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub


Thanks both, each suggestion made it work. Thanks for your help!
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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