Copy and Rename an Excel Worksheet with a Date Using VBA
Question details
Copy the active Excel worksheet within the same workbook and give the copy a date-based, user-entered, or cell-based name.

- 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.
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.
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.
In Excel, select Developer > Visual Basic. If the Developer tab is hidden, enable it through Excel's ribbon settings.
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
Return to Excel, select the worksheet to copy, then choose Developer > Macros, select CopySheetWithDate, and click Run.

Name the copied worksheet from a prompt or cell
Use this version when the copy needs a custom name instead of today's date.
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.

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.




