VBA Changing same cell in multiple sheets while adding a number each time

SereneSea

New Member
Joined
Feb 2, 2022
Messages
43
Office Version
  1. 2016
Platform
  1. Windows
I am looking for a VBA code that will change multiple sheets at once while adding 7 each time.
My sheets are all labelled Week-1, Week 2 up to Week 53 and each time I batch duplicate I would like to be able to change my Cell C2 to add 7 days.

Ie. In the Week 2 sheet, C2 is Jan 3 2022, I would like Week-3 Sheet to be automatically labelled Jan 10 2022 and so on.

Is there an easy code to do this?
 
I would like 1/14/2022 in the next sheet, then the next sheet 1/21/2022 then the next sheet to have 1/28/2022 and so on. Basically each new sheet to have a new Monday start is C2.

VBA Code:
Sub Copypastesheets()
    'Modified  2/2/2022  8:47:28 PM  EST
    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
    Dim r As String
    r = ActiveSheet.Range("C2").value + 7
    xNumber = InputBox("Enter number of times to copy the current sheet")
    For i = 1 To xNumber
        xName = ActiveSheet.Name
        xActiveSheet.Copy After:=ActiveWorkbook.Sheets(xName)
        ActiveSheet.Range("C2").value = r
        ActiveSheet.Name = "Week-" & i
        
        
           Next
    xActiveSheet.Activate
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Sorry I was confused
Try this:
VBA Code:
Sub Copypastesheets()
    'Modified  2/3/2022  12:21:21 PM  EST
    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
    Dim r As Long
    r = ActiveSheet.Range("C2").Value
    xNumber = InputBox("Enter number of times to copy the current sheet")
    For i = 1 To xNumber
        r = r + 7
        xName = ActiveSheet.Name
        xActiveSheet.Copy After:=ActiveWorkbook.Sheets(xName)
        ActiveSheet.Range("C2").Value = r
        ActiveSheet.Name = "Week-" & i
        
        
           Next
    xActiveSheet.Activate
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Solution
YES! Thank you so so much!!! This saves me so much time!
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,619
Members
449,240
Latest member
lynnfromHGT

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