Hi everyone,
i have a lot of excel sheets and have inserted 2 as examples.
All sheets end with -q1 or -q2 etc.
The workbooks contain sheets, which all have the same names.
I would like to copy the sheets with the same names together, i.e. the contents of the sheets that have the same name should be copied next to each other.
For this purpose I would like to select the workbooks that should be copied together with a popup window.
The endings of the worksheets could help to determine the order.
The selected workbooks and the sheets with the same name should be copied in descending order.
I.e. the contents of the sheet with the name 'Cash Flow' from Q7 is copied behind the sheet with the name 'Cash Flow' from Q8; the sheet with the name 'Cash Flow' from Q6 is copied behind the sheet with the name 'Cash Flow' from Q7 and so on.
In total there can be 16 sheets, i.e. the sheet with the ending -q16 is the last one.
I have a code that does this in principle but only for one workbook. I need to copy several workbooks at the same time.
The code also copies the Workbooks beneath each other and not side by side.
I need the workbooks side by side.
I hope you can help me.
Thank you very much.
Here is the Code I have:
Sub KOPIERE_Sheets_WITH_SAME_SHEET_NAME_FROM_OTHER_WORKBOOK_AND_ALL_OTHER()
Application.ScreenUpdating = False
Dim flder As FileDialog, FileName As String, FileChosen As Integer, wkbDest As Workbook, wkbSource As Workbook, WS As Worksheet
Set wkbDest = ThisWorkbook
Set flder = Application.FileDialog(msoFileDialogFilePicker)
flder.Title = "Please Select a folder and file."
FileChosen = flder.Show
FileName = flder.SelectedItems(1)
Set wkbSource = Workbooks.Open(FileName)
With wkbSource
For Each WS In .Sheets
If Not IsError(Evaluate("=ISREF('[" & wkbDest.Name & "]" & WS.Name & "'!$A$1)")) Then
WS.UsedRange.Cells.Copy
With wkbDest.Sheets(WS.Name).Cells(wkbDest.Sheets(WS.Name).Rows.Count, "A").End(xlUp).Offset(2)
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
End With
Else
WS.Copy after:=wkbDest.Sheets(wkbDest.Sheets.Count)
End If
Next WS
End With
wkbSource.Close False
Application.ScreenUpdating = True
End Sub
Bookmarks