VBA & Macro Problems

How to Automatically Rename 52 Excel Worksheets with Weekly Dates

Maira MehtabMaira Mehtab Oct 28, 2026 869 views

Question details

The user needs a way to automatically rename 52 worksheets in an Excel workbook with consecutive weekly Sunday dates for the year 2023.

How to Automatically Rename 52 Excel Worksheets with Weekly Dates
Product
Excel
Device & OS
not provided
Scenario
Organizing a weekly tracking workbook that contains 52 sheets, where manually renaming each sheet to a specific date is too time-consuming.
Observed behavior
The goal state is to execute a script or process that programmatically assigns a formatted date (such as the Sunday of each week) to each of the 52 worksheets without utilizing invalid characters like slashes.
Before you start

Before running the macro, ensure your workbook actually contains at least 52 blank or existing worksheets to avoid script errors, and always save a backup copy of your file.

Solution 1Recommended

Use a VBA Macro to Rename Sheets Automatically

Using a simple VBA script is the fastest and most reliable way to batch rename multiple sheets with incrementing dates in Excel.

Excel worksheet names cannot contain certain characters like slashes (/). The macro formats the dates with hyphens (e.g., 1-Jan-2023) to comply with this naming rule and ensure the script runs smoothly.

1
Open the VBA Editor

Press the ALT + F11 keys simultaneously on your keyboard to open the Microsoft Visual Basic for Applications (VBA) window.

2
Insert a New Module

From the top menu, click 'Insert' and select 'Module'. This will open a blank window where you can write or paste your code.

3
Paste the Macro Code

Copy and paste the following code into the module window: Sub NameSheets() Dim i As Long Dim d As Date Application.ScreenUpdating = False d = DateSerial(2023, 1, 1) For i = 1 To 52 Worksheets(i).Name = Format(d, "d-mmm-yyyy") d = d + 7 Next i Application.ScreenUpdating = True End Sub

4
Run the Macro

Press F5 or click the 'Run' button (the green play icon) on the top toolbar. Return to your workbook to see the first 52 sheets instantly renamed.

Macro Customization: You can change the starting date by modifying the DateSerial(2023, 1, 1) line to your desired starting year, month, and day.
Automate with WPS

Automate Your Workflow Seamlessly with WPS Spreadsheet

WPS Spreadsheet offers robust tools to organize, format, and manage large workbooks effortlessly. You can natively run macros and handle advanced formatting without missing a beat.

  1. 1. Open Your Workbook: Launch WPS Spreadsheet and open your existing file containing the 52 worksheets.
  2. 2. Access Developer Tools: Navigate to the 'Developer' tab on the top ribbon to access the built-in Macro tools.
  3. 3. Open the VBA Editor: Click 'Macros' and open the VBA Editor to insert a new code module.
  4. 4. Run the Automation: Paste your custom date-generation macro code and click 'Run' to batch rename your sheets in seconds.
Fully compatible with Microsoft Excel (.xlsx and .xlsm) macro-enabled formats.Lightweight design ensures smooth performance even with workbooks containing 50+ sheets.Built-in developer tools for seamless VBA macro execution and automation.
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get an error when naming an Excel sheet with a date?

Excel restricts certain characters in worksheet names, including slashes (/), backslashes (\), asterisks (*), and question marks (?). Always use hyphens (-) or periods (.) when formatting dates for sheet names to prevent naming errors.

How can I change the date format in the VBA macro?

You can modify the format string in the 'Format' function within the code. For example, changing "d-mmm-yyyy" to "yyyy-mm-dd" will format the date as 2023-01-01 instead of 1-Jan-2023.

What happens if I have fewer than 52 sheets when running the macro?

The macro will produce a 'Subscript out of range' error when it tries to rename a sheet index that does not exist in the workbook. Ensure you have the exact number of sheets specified in the loop, or adjust the 'For i = 1 To 52' line to match your actual sheet count.

How do I start on a different day of the week instead of Sunday?

You simply need to adjust the DateSerial(year, month, day) function in the VBA code to correspond to the exact calendar date of the specific day you want to start on.