VBA & Macro Problems

Fix Excel VBA Not Renaming a Newly Added Worksheet

Maira MehtabMaira Mehtab Nov 18, 2026 869 views

Question details

The user needs to rename a worksheet immediately after creating it with Excel VBA.

Fix Excel VBA Not Renaming a Newly Added Worksheet
Product
Microsoft Excel VBA
Device & OS
not provided
Scenario
A VBA macro adds a worksheet and should assign a specified name to its tab.
Observed behavior
The worksheet is created, but its tab does not receive the expected name, including when a literal string or a variable is used.
Before you start

Check the target workbook and the intended worksheet name before running the macro. Worksheet names must be unique within the workbook, contain no more than 31 characters, and cannot include these characters: \ / ? * [ ] :.

Solution 1Recommended

Store the New Worksheet Reference Before Renaming It

Use an explicit worksheet reference to ensure the name is assigned to the sheet the macro just created.

ThisWorkbook refers to the workbook containing the macro, which may differ from the active workbook. Use the intended workbook reference if the new sheet belongs elsewhere.

This approach may not resolve the issue by itself if the same code already fails in your workbook. Use the test and troubleshooting steps below to isolate the cause.

1
Open the VBA editor

In Excel, open Developer > Visual Basic, then open the module containing your macro.

2
Assign and rename the sheet

Use an object variable when adding the sheet, for example: Dim ws As Worksheet Dim destSht As String destSht = "Hello World" Set ws = ThisWorkbook.Worksheets.Add ws.Name = destSht

3
Run and inspect the macro

Run the macro from the VBA editor and check the new tab in the workbook containing the code. If an error appears, select Debug to inspect the highlighted line and the value of destSht.

4
Check workbook restrictions

If adding or renaming is blocked, check Review > Protect Workbook for workbook structure protection and remove it if you have permission.

Store the New Worksheet Reference Before Renaming It
Free Microsoft Office alternative

Work With Excel Spreadsheets in WPS Office

WPS Office is a free, lightweight alternative for everyday spreadsheet work, with a familiar interface and support for common Excel formats to help you move between office suites. It does not repair Excel or guarantee compatibility with every VBA macro.

Open and edit spreadsheets with a familiar interfaceWork with Microsoft Excel formats such as XLSX and XLSOrganize worksheet tabs for everyday spreadsheet tasksUse a free, lightweight office suite
QA img-9

Frequently Asked Questions

Why does my macro create a sheet but leave its default name?

The rename line may be targeting a different sheet, not executing, or encountering an error. Store the result of Worksheets.Add in a Worksheet variable, set its Name, and use Debug in the VBA editor to inspect any error.

Does ThisWorkbook mean the workbook I currently have open?

ThisWorkbook is the workbook containing the VBA code. It may not be the active workbook. Use a reference to the intended workbook when calling Worksheets.Add.

What makes an Excel worksheet name invalid?

A worksheet name must be unique within the workbook, be no more than 31 characters, and cannot contain \ / ? * [ ] :. Check the value of your name variable before assigning it.

How can I tell whether an add-in is causing the problem?

On Windows, start Excel with excel /safe from the Windows+R dialog and run the macro. If it works in Safe Mode, check File > Options > Add-ins and disable add-ins to isolate the conflict.