I found here the code below which does exactly what I need and that is loop through sheets of a source workbook, copy a range of data and paste to another workbook where sheets have the same name of the source wb. Works perfectly until it comes to different named sheets where I get an error message "out of range". How can I skip this? Furthermore there are two sheets (TOTALS & GENERAL) that I want the code to skip them and run only through all other sheets. Thank you in advance for your kind help.
VBA Code:
Sub Button1_Click()
Dim SourceWb As Workbook, DestWb As Workbook
Dim SourceWs As Worksheet, DestWs As Worksheet
Dim WsName As String
Dim CopyRng As Range
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set SourceWb = ThisWorkbook
'Set SourceWs = SourceWb.Worksheets
Set DestWb = Workbooks.Open("C:\Users\Juanna\Desktop\downloads\master.xlsx", , True) 'Readonly = True
'Loop through all worksheets and copy the data to the DestWs
For Each SourceWs In SourceWb.Worksheets
'Fill in the range that you want to copy
Set CopyRng = SourceWs.Range("b1:c10")
Set DestWs = DestWb.Worksheets(SourceWs.Name)
With CopyRng
DestWs.Cells(Last + 1, "b").Resize(.Rows.Count, .Columns.Count).Value = .Value
End With
Next
ExitTheSub:
Application.Goto DestWs.Cells(1)
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub