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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

ExpExchHelpAnalystAuthor Commented:
Sorry, this doesn't work.
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.
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

ExpExchHelpAnalystAuthor 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.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ExpExchHelpAnalystAuthor Commented:
Fabrice -- thank you so, much... this solution works great!!!   I appreciate your assistance/help.  :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.