In order to get the beautiful part, looking like the picute below, a few more steps are needed:
VBA
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Sub CopyWorksheetsBeautiful() Dim wks As Worksheet Dim wkb As Workbook Set wkb = Workbooks.Add wkb.SaveAs "NewCopyWithReference.xlsx" ReDim myArr(ThisWorkbook.Worksheets.Count - 1) Dim i As Long For i = 0To ThisWorkbook.Worksheets.Count - 1 myArr(i) = ThisWorkbook.Worksheets(i + 1).Name Next i ThisWorkbook.Worksheets(myArr).Copy wkb.Worksheets(Worksheets.Count) EndSub
PublicSub CopyWorksheets() Dim wksCollection As New Collection wksCollection.Add ThisWorkbook.Worksheets("SheetA") wksCollection.Add ThisWorkbook.Worksheets("SheetB") wksCollection.Add ThisWorkbook.Worksheets("SheetC") Dim wks As Worksheet Dim newWks As Worksheet ForEach wks In wksCollection Dim newName As String newName = wks.Name & "_w" If WorksheetNameIsPresent(newName) Then Application.DisplayAlerts = False Worksheets(newName).Delete Application.DisplayAlerts = True EndIf wks.Copy after:=Worksheets(Worksheets.Count) Set newWks = Worksheets.Item(Worksheets.Count) With newWks .Name = newName .Tab.Color = 255 EndWith Next wks EndSub