Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Dynamic Worksheet Tab Names.
by Allen Wyatt
(last updated November 4, 2017)
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 simple 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 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.
There is one caveat to using this tip: If the value in cell A1 is a date and you want the worksheet tab to contain that date, then you may not get what you expect. The reason is simple: Excel stores dates internally as serial numbers, and that is what gets assigned to the worksheet tab, not a formatted date. If you are working with dates, then you'll need to change what actually is assigned to the tab name:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) Set Target = Range("A1") If Target = "" Then Exit Sub On Error GoTo Badname ActiveSheet.Name = Format(Target, "mmm-dd-yy") 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
Note that the only change here is what is assigned to the worksheet's Name property—it is a formatted date. You can, if you prefer, modify the date format used in the macro. You should not, however, choose a format that uses slashes because those are illegal in worksheet names.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7993) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Dynamic Worksheet Tab Names.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
By default, a new Excel workbook contains three blank worksheets. You can (and should) configure Excel to whatever number ...Discover More
Ever want to use the name of a worksheet tab within a cell? Here's how you can access that information using the CELL ...Discover More
Freezing the top rows in a worksheet so that they are always visible is easy to do. Freezing the bottom rows is not so ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.