Dynamic naming (renaming) of worksheet tabs


I have come across multiple posting which dynamically update a tab/sheet name based on a given cell value.   Unfortunately, I have not come across a solution what would address my specific requirement.

Attached XLS contains VBA code where a change in cell A1 updates Sheet1's tab's name from (currently) "Alaska" to the new name.

Here's what I need some help with:
1. I need the same functionality for Sheet1 to also work for additional worksheets.
2. While I could copy the VBA from Sheet1 into each of the other three worksheets, I would have to manually update the cell reference to A2, A3, A4 for Sheet2 through Sheet4, respectively.  I don't want that!
3. Next, current Sheet1 (Alaska) will actually become the master sheet.   That is, I want the values in column A (of Sheet1) drive the values in other worksheets of the spreadsheet.
4. Finally, when adding a new sheet (e.g., "Sheet 5"), I would prefer to automatically have the dynamic capability to change the sheet's name based on my simply adding a new value into A5 (Sheet1) ** WITHOUT ** having to go into the VBA for Sheet5 and make required modifications.

Can the above requirements coded into Excel?  If so, how?

Thank you,
Who is Participating?
Fabrice LambertFabrice LambertCommented:
Alright, my apologies for the confusion.

Since the cell's row match the sheet's numer (A1 ==> name of 1st sheet, A2 ==> name of 2nd sheet ect ect .... and so on), we can work on the sheet1 change event, check the cell's column and value, get the cell's row that will be the index of sheet's number.
Short code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim wb As Excel.Workbook
    Dim row As Long
    If ((Target.Column = 1) And ((Target.Value & vbNullString) <> vbNullString)) Then
        Set wb = ThisWorkbook
        row = Target.row
        wb.Worksheets(row).Name = Target.Value
        Set wb = Nothing
    End If
End Sub

Open in new window

Fabrice LambertFabrice LambertCommented:

You can use the workbook sheetChange event.
Try this in the workbook module:
Option Explicit

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    If (Target.Address = Sh.Range("A1").Address) Then
        Sh.Name = Target.Value
    End If
End Sub

Open in new window

ExpExchHelpAuthor Commented:
Sorry, this doesn't work.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Fabrice LambertFabrice LambertCommented:
No clue what you did, and a simple "doesn't work" won't help without explanations.

Where did you copy the code ?
Did you try debugging ?
Did you inspect variables ?
Did you recieve an error ? wich one ? wich line trigger it ?
Did you get incorrect results ? What results ect ect .... the more you provide, the better.

After much testing, I found no problems.
See the attached file, and compare with what you did.
ExpExchHelpAuthor Commented:

First, let me say that I thank you for your assistance.

I copied your code and downloaded your XLS example.   Neither don't work based on the requirements specified in the original posting.

Quick recap... the code needs to work to update multiple tabs.   So, while changing "Alaska" (in A1) to, e.g., "AA" does change Sheet1 to "AA".   However, changing "California" (in A2) to, e.g., "BB" does NOT change Sheet2, and so forth (for the remainder of the worksheets.

I'd welcome any ideas you may have.

ExpExchHelpAuthor Commented:
Fabrice -- thank you so, much... this solution works great!!!   I appreciate your assistance/help.  :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.