Insert sheets into a workbook and increment cell values on each sheet

Bagsy

Active Member
Joined
Feb 26, 2005
Messages
467
Office Version
  1. 365
Platform
  1. Windows
Hopefully somebody can help a bit here I have some code which copies the first sheet and inserts the required number of copies into the workbook.
This works great but what I would like to achieve is this
The first sheet Row 17 columns P-T are numbered 1,2,3,4,5. and I would like to each of these cells to increment for each sheet as it is copied.
Example
Sheet 1 Row 17 columns P-T numbered 1,2,3,4,5
Sheet 2 Row 17 columns P-T numbered 6,7,8,9,10
Etc for the number of sheets you require. I’m not sure if this is possible as I am having trouble finding any information to give me a start.
Any help is always appreciated
Code below
VBA Code:
Sub CreateSheets()
'this will enter the number of sheets required from input box and rename them
Dim I As Long
Dim xNumber As Integer
Dim xName As String
Dim xActiveSheet As Worksheet
On Error Resume Next
Application.ScreenUpdating = False
Set xActiveSheet = ActiveSheet
xNumber = InputBox("Enter Number of Sheets Required")
For I = 2 To xNumber
xName = ActiveSheet.Name
xActiveSheet.Copy After:=ActiveWorkbook.Sheets(xName)
ActiveSheet.Name = "Page " & I
Next
xActiveSheet.Activate
Application.ScreenUpdating = True
End Sub
Screenshot 2022-02-03 123016.png
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Please see the changes below.

VBA Code:
Sub CreateSheets()
'this will enter the number of sheets required from input box and rename them
Dim I As Long
Dim xNumber As Integer
Dim xName As String
Dim xActiveSheet As Worksheet
Dim j As Long           '// Added
Dim arrNum(1 To 5)      '// Added

On Error Resume Next
Application.ScreenUpdating = False
Set xActiveSheet = ActiveSheet
xNumber = InputBox("Enter Number of Sheets Required")
For I = 2 To xNumber
    xName = ActiveSheet.Name
    xActiveSheet.Copy After:=ActiveWorkbook.Sheets(xName)
    ActiveSheet.Name = "Page " & I
    
    '// Added
    For j = 1 To 5
        arrNum(j) = 5 * (I - 1) + j
    Next j
    ActiveSheet.Range("P17:T17") = arrNum
    '// End Added
    
Next I
xActiveSheet.Activate
Application.ScreenUpdating = True
End Sub

Hope that helps.

Regards,
Ken
 
Upvote 0
Solution
Ken
That is just amazing, I didn't think it could be done, thank you so much.
Gary
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

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