Written by Allen Wyatt (last updated May 13, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365
Peter developed a macro that deletes all the worksheets in a workbook except for one named "Index." This macro works fine. However, after running the macro, if he adds a new worksheet he expects it to be named "Sheet1" as the default, but it is actually named a later number, such as "Sheet3" or "Sheet4." Peter wonders what is required to reset the sheet numbering to the expected default.
The easiest way to reset the sheet numbering is to simply close the workbook and open it again. That, however, involves a manual step on your part. If you are adding the new worksheets via macro, then you probably don't want to manually close and re-open the workbook.
You could, if desired, create a simple macro to do the close and re-open process. This will work as long as the macro is stored in your Personal Macro Workbook and not in the workbook you are closing.
Sub Reopen() Dim wb As Excel.Workbook Dim sPath As String Set wb = ThisWorkbook sPath = wb.FullName Application.OnTime Now + TimeValue("00:00:01"), _ Application.Workbooks.Open(sPth) wb.Close (True) End Sub
The macro determines the name of the current workbook and then sets an OnTime event to open the workbook 1 second in the future. During that 1 second, however, the workbook is closed and saved, which allows it to be re-opened successfully.
You could, if desired, also choose to add your new worksheets via macro. The following short macro adds a worksheet and then immediately renames it to the desired name.
Sub AddWs() Worksheets.Add after:=Sheets(Sheets.Count) Sheets(Sheets.Count).Name = "Sheet" & Sheets.Count - 1 End Sub
You'll want to play with these solutions and find which one works best for your needs, particularly if you are wanting to integrate the solution with an already existing macro.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (6103) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
Got a macro that doesn't have quite the right name? You can rename the macro by following these simple steps.
Discover MoreIt can be frustrating when you get error messages doing something that you previously did with no errors. If you get an ...
Discover MoreMacros can be used to change the formatting of your worksheet, if desired. One change you might want to make is to the ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments