Hi! I have this code to copy multiple worksheets to another workbook :
Is there a way to make this more dynamic and allow you to list and select the worksheet names from a range? The conditions are:
1. The worksheet names change in every source file, and the order matters: ABC, DEF, then GHI for example. Was thinking having the list might help with this?
2. All destination files have a worksheet called “JKL” and the 3 copied worksheets need to come before it. JKL is the first worksheet in the destination file if that helps.
2. The source and destination file names always change.
3. This macro will be in a separate file where we can select the range from.
Thanks in advance!
VBA Code:
Sub Copy_to_Another_Multiple()
Dim Source As String
Dim Destination As String
Source = “Filename1.xlsx”
Destination = “Filename2.xlsx”
Dim Worksheets As Variant
ReDim Worksheets (3)
Worksheet(1) = “ABC”
Worksheet(2) = “DEF”
Worksheet(3) = “GHI”
Dim i as Variant
For i = 1 To UBound (Worksheets)
Workbooks(Source).Sheets(Worksheets(i)). Copy
before:=Workbooks(Destination).Sheets(“JKL”)
1. The worksheet names change in every source file, and the order matters: ABC, DEF, then GHI for example. Was thinking having the list might help with this?
2. All destination files have a worksheet called “JKL” and the 3 copied worksheets need to come before it. JKL is the first worksheet in the destination file if that helps.
2. The source and destination file names always change.
3. This macro will be in a separate file where we can select the range from.
Thanks in advance!