Forum Discussion
How to rename the worksheet tabs
- Jun 11, 2021
If you save the workbook with the original sheet names Sheet1, Sheet2 etc. as a macro-enabled template (.xltm), you can create a new workbook from the template each month.
(You could also save the workbook under a new name at the end of the macro, so that the original remains unchanged)
Try this. Warning: you can run the macro only once.
Sub RenameSheet()
Dim i As Long
Dim n As Long
For i = 1 To 23
On Error Resume Next
Worksheets("Sheet" & i).Name = Format(Worksheets("Daily Totals").Range("A" & i + 3), "Short Date")
If Err Then
n = n + 1
Worksheets("Sheet" & i).Name = "NotUsed" & n
End If
Next i
End Sub- VickieMoody777Jun 11, 2021Copper Contributor
Hello HansVogelaar:
Thank you for the code and it did work. But I do need to have the macro available every month so I could use it every month when I update the tabs to a new month.
Thank you!
- HansVogelaarJun 11, 2021MVP
If you save the workbook with the original sheet names Sheet1, Sheet2 etc. as a macro-enabled template (.xltm), you can create a new workbook from the template each month.
(You could also save the workbook under a new name at the end of the macro, so that the original remains unchanged)
- VickieMoody777Jun 11, 2021Copper ContributorHello HansVogelaar
Ok, I am not sure what is happening, but now all the sheets are naming not used. Is it because of the For i = 1 To 23 command? What am i doing wrong?