VBA & Macro Problems

Copy and Rename an Excel Worksheet with a Date Using VBA

John WilsonJohn Wilson Nov 27, 2026 868 views

Question details

Copy the active Excel worksheet within the same workbook and give the copy a date-based, user-entered, or cell-based name.

Copy and Rename an Excel Worksheet with a Date Using VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
A user wants a VBA macro that duplicates the current worksheet and assigns a chosen name to the copy.
Observed behavior
The desired result is a copied worksheet placed after the active sheet in the same workbook, with the specified name.
Before you start

Open the workbook in Excel and select the worksheet you want to copy. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) if you want to retain the macro, and enable macros only if you trust the file.

Solution 1Recommended

Copy the active worksheet and name it with today's date

Use this macro to place a copy immediately after the active worksheet and name it in YYYYMMDD format.

1
Open the VBA editor

In Excel, select Developer > Visual Basic. If the Developer tab is hidden, enable it through Excel's ribbon settings.

2
Insert the macro

In the VBA editor, select Insert > Module and paste: Sub CopySheetWithDate() Dim sourceSheet As Worksheet Dim newSheet As Worksheet Dim ws As Worksheet Dim sheetName As String Set sourceSheet = ActiveSheet sheetName = Format(Date, "yyyymmdd") For Each ws In sourceSheet.Parent.Worksheets If StrComp(ws.Name, sheetName, vbTextCompare) = 0 Then MsgBox "A worksheet named " & sheetName & " already exists." Exit Sub End If Next ws On Error GoTo CopyError sourceSheet.Copy After:=sourceSheet Set newSheet = ActiveSheet newSheet.Name = sheetName Exit Sub CopyError: MsgBox "Could not copy or rename the worksheet: " & Err.Description End Sub

3
Run the macro

Return to Excel, select the worksheet to copy, then choose Developer > Macros, select CopySheetWithDate, and click Run.

Copy the active worksheet and name it with today's date
Existing date names: If a worksheet already has today's date as its name, the macro stops before copying. Rename the existing sheet or change the date format in the code before running it again.
Free Microsoft Office alternative

Copy and Rename Worksheets in WPS Spreadsheet

WPS Office is a free, lightweight Office alternative with a familiar interface and Excel format support for an easier transition. In WPS Spreadsheet, you can copy a sheet from its tab menu and rename the copy manually; this does not fix Excel's VBA behavior.

Copy and rename worksheet tabs for date-based recordsOpen and edit Microsoft Excel formats, including .xlsxUse a familiar spreadsheet interface when moving from ExcelWork with a free, lightweight Office suite
microsoft office alternative - wps office

Frequently Asked Questions

How do I keep the copied worksheet in the same workbook?

Use sourceSheet.Copy After:=sourceSheet. The After argument places the copy immediately after the source sheet in its existing workbook.

Why does the date-based macro stop without copying a sheet?

The macro checks for an existing worksheet with the same YYYYMMDD name. Rename that sheet or change the Format(Date, "yyyymmdd") expression before running the macro again.

Can I use a cell value as the copied sheet's name?

Yes. In the custom-name macro, replace the InputBox assignment with sheetName = Trim(sourceSheet.Range("A1").Text), changing A1 to the cell you want to use.

What names are invalid for an Excel worksheet?

Names cannot be blank, exceed 31 characters, or contain :, \, /, ?, *, [, or ]. Excel also rejects some other names, including names that begin or end with an apostrophe.

How do I save the macro for later use?

In Excel, choose File > Save As and select Excel Macro-Enabled Workbook (.xlsm). Enable macros when reopening the file only if you trust it.