UserPrabha
New Member
- Joined
- Jul 7, 2023
- Messages
- 1
- Office Version
- 2016
- Platform
- Windows
I am trying to run this code, it successfully copies the first two sheets and then throws up Error 9. This is my code.
This is where the error subscript out of range is pointing to . Can you please help
VBA Code:
Sub Copy_Multiple_Sheets()
Dim Source As String
Dim Destination As String
Source = "TR B.xlsx"
Destination = "Load B.xlsx"
Dim Worksheets As Variant
ReDim Worksheets(12)
Worksheets(1) = "apr"
Worksheets(2) = "may"
Worksheets(3) = "june"
Worksheets(4) = "Jul"
Worksheets(5) = "Aug"
Worksheets(6) = "Sep"
Worksheets(7) = "oct"
Worksheets(8) = "nov"
Worksheets(9) = "dec"
Worksheets(10) = "jan"
Worksheets(11) = "feb"
Worksheets(12) = "mar"
Dim i As Variant
For i = 1 To UBound(Worksheets)
Workbooks(Source).Sheets(Worksheets(i)).Copy _
After:=Workbooks(Destination).Sheets(Workbooks(Destination).Sheets.count)
Next i
End Sub
This is where the error subscript out of range is pointing to . Can you please help
VBA Code:
Workbooks(Source).Sheets(Worksheets(i)).Copy _
After:=Workbooks(Destination).Sheets(Workbooks(Destination).Sheets.count)
Last edited by a moderator: