Nov 04 2022 06:01 AM
How can I create and name 26 sheets at the same time?
I need to date them two weeks apart, starting with the date of the second Friday in January - January 13, 2023. The sheets following need to be dated 2 weeks apart, i.e. January 27, Feb. 10, Feb. 24, March 10, etc.
The date format doesn't matter but, my preference would be: Jan 13, Jan 27, Feb 24...........and so on. The file will be named with the year 2023.
Nov 04 2022 07:36 AM
You can run this macro:
Sub CreateSheets()
Dim y As Long
Dim w As Long
Dim d As Date
Dim i As Long
y = InputBox(Prompt:="Enter the year", Default:=Year(Date) + 1)
w = Weekday(DateSerial(y, 1, 1), vbSaturday)
d = DateSerial(y, 1, 1) + 14 - w
Application.ScreenUpdating = False
For i = 0 To 25
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = Format(d + 14 * i, "mmm d")
Next i
Application.ScreenUpdating = True
End Sub
Dec 30 2022 04:19 AM - edited Dec 30 2022 07:50 AM
I have never run a macro in Excel before. I googled for instructions but, cannot find out how to do this specific macro. Would you mind giving me step by step instructions?
Dec 30 2022 04:30 AM
Press Alt+F11 to activate the Visual Basic Editor.
Select Insert > Module.
Copy the code from my previous reply, and paste it into the code module.
Click anywhere in the code, then press F5 to run it.
Switch back to Excel and inspect the result.
You probably won't need to run the macro again. When you close and save the workbook, Excel will display a warning. Click Yes to save the workbook anyway.
Dec 30 2022 07:47 AM
Feb 08 2024 06:37 AM
Feb 08 2024 07:31 AM
Let's say you have a sheet named Template.
Change the macro as follows:
Sub CreateSheets()
Dim y As Long
Dim w As Long
Dim d As Date
Dim i As Long
y = InputBox(Prompt:="Enter the year", Default:=Year(Date) + 1)
w = Weekday(DateSerial(y, 1, 1), vbSaturday)
d = DateSerial(y, 1, 1) + 14 - w
Application.ScreenUpdating = False
For i = 0 To 25
Worksheets("Template").Copy(After:=Worksheets(Worksheets.Count))
Worksheets(Worksheets.Count).Name = Format(d + 14 * i, "mmm d")
Next i
Application.ScreenUpdating = True
End Sub