Sequentially Number copies of template worksheet

jwb1012

Board Regular
Joined
Oct 17, 2016
Messages
167
Hello, I am using the following code to create multiple copies of a template, based on the "number of copies required" which is determined by a formula in cell D10 on the "Staffing Plan" worksheet.

If D10 = 5, then it will make 5 copies. It then renames the worksheets to give me: Report 1 of 5, Report 2 of 5, Report 3 of 5, Report 4 of 5, and Report 5 of 5.

I am wondering if its possible to also sequentially number the worksheets in cell A1. So, in cell A1 of each of these worksheets would have a number (1, 2, 3, 4, and 5). I need this number because the template (and the copies generated) is set up to do vlookups off of cell A1.


Code:
Sub Copy_Template()
    Dim Sh As Worksheet
    Dim i As Integer
    Dim i2 As Integer
    Dim X As Integer
        
        'Set sheet to copy
        Set Sh = Worksheets("Template")
        
            'Determine number of copies to make
            i = Worksheets("Staffing Plan").Range("D10")
        
                'Name the first sheet
                Sh.Name = "Template"
        
                    i2 = ActiveWorkbook.Worksheets.Count
                        For X = 1 To i
                            Sh.Copy After:=Sheets(i2 + X - 1)
                            'Name of subsequent sheets
                            Sheets(X + i2).Name = "Report " & X & " of " & i
                            
                        Next X
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I am wondering if its possible to also sequentially number the worksheets in cell A1. So, in cell A1 of each of these worksheets would have a number (1, 2, 3, 4, and 5).

Code:
                    i2 = ActiveWorkbook.Worksheets.Count
                        For X = 1 To i
                            Sh.Copy After:=Sheets(i2 + X - 1)
                            'Name of subsequent sheets
                            Sheets(X + i2).Name = "Report " & X & " of " & i
                            [COLOR="#0000CD"][B]Sheets(X + i2).Range("A1").Value = X[/B][/COLOR]
                        Next X
End Sub
Untested, but it seems to me that adding the blue line above should do that for you.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

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