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.
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