Create new workbook with copied sheet 'x' amount of times

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,592
Office Version
  1. 365
Platform
  1. Windows
Hi all

Can anybody give some code that will do the following

1> copy sheet2 from active workbook
2> open new workbook
3> add the copied Sheet2 to the new workbook multiplied by the number shown in cell G2 of sheet "Display" in the original workbook.
4> Then rename each new sheet 1,2,3,4,5, etc NOT SHEET1, SHEET2 etc

EDIT:

I just found this code online to rename the sheets 1,2,3,4,5 etc

Code:
Sub renameSheets()
Dim iSheetCount

    For iSheetCount = 1 To Sheets.Count
        Sheets(iSheetCount).Name = iSheetCount
    Next iSheetCount

End Sub

So for example if G2 holds the number 15, the 'Display' sheet will be copied 15 times into the new workbook and they will then be renamed 1-15

So if anybody could adapt the above code to carry out steps 1-3 as above first I think that might work

many thanks
 
Last edited:

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Think I've got it....

Code:
Sub copy()
    Set NewBook = Workbooks.add
    ThisWorkbook.Sheets("Template").copy Before:=NewBook.Sheets(1)
    Sheets("Template").Select
    Set baseSheet = ActiveSheet
    howmany = Range("A1")
    For i = 2 To howmany
    baseSheet.copy after:=Worksheets(Worksheets.Count)
    ActiveSheet.Name = Format(Date + i, "dd")
    Next i
    
    Application.DisplayAlerts = False
    Sheets("Sheet1").Delete
    Application.DisplayAlerts = True
    
    Dim iSheetCount
    For iSheetCount = 1 To Sheets.Count
    Sheets(iSheetCount).Name = iSheetCount
    Next iSheetCount



    End Sub

note: I have changed some sheet names but this seems to do the trick
 
Upvote 0

Forum statistics

Threads
1,203,552
Messages
6,056,053
Members
444,841
Latest member
SF_Marnie

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top