Written by Allen Wyatt (last updated October 16, 2021)
This tip applies to Excel 97, 2000, 2002, and 2003
You probably already know that you can change the name of a worksheet tab by double-clicking on the tab and providing a new name. What if you want to do it dynamically, however? What if you want to have the value in cell A1 automatically appear as the tab name?
Unfortunately, Excel doesn't provide an intrinsic function to handle this sort of task. It is a relatively simply task to develop such a function using a macro that will do the job for you. For instance, the following macro will change the tab name to the contents of A1:
Sub myTabName() ActiveSheet.Name = ActiveSheet.Range("A1") End Sub
There are several important items to note about this macro. First of all, there is no error checking. This means that if A1 contains a value that would be illegal for a tab name (such as nothing at all or more than 31 characters), then the macro generates an error. Second, the macro must be manually run.
What if you want a more robust macro that does check for errors and runs automatically? The result is a bit longer, but still not overly complex:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) Set Target = Range("A1") If Target = "" Then Exit Sub On Error GoTo Badname ActiveSheet.Name = Left(Target, 31) Exit Sub Badname: MsgBox "Please revise the entry in A1." & Chr(13) _ & "It appears to contain one or more " & Chr(13) _ & "illegal characters." & Chr(13) Range("A1").Activate End Sub
To set up this macro, follow these steps:
Now, anytime you change the value in cell A1, the worksheet tab also updates.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2145) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Dynamic Worksheet Tab Names.
Best-Selling VBA Tutorial for Beginners Take your Excel knowledge to the next level. With a little background in VBA programming, you can go well beyond basic spreadsheets and functions. Use macros to reduce errors, save time, and integrate with other Microsoft applications. Fully updated for the latest version of Office 365. Check out Microsoft 365 Excel VBA Programming For Dummies today!
If your workbook contains a multitude of worksheets, the worksheet tabs at the bottom of the program window start to ...
Discover MoreDo you need your worksheet tabs to be taller than what they are? You can't make the adjustment in Excel, but you can make ...
Discover MoreWant to grab the names of all the worksheets in a workbook? Here's how you can stuff all those names into the cells of a ...
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 menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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