Link to home
Start Free TrialLog in
Avatar of ExpExchHelp
ExpExchHelpFlag for United States of America

asked on

Dynamic naming (renaming) of worksheet tabs

Experts:

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,
EEH
Dynamic-Worksheet-Renaming.xlsm
Avatar of Fabrice Lambert
Fabrice Lambert
Flag of France image

Hi,

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

Avatar of ExpExchHelp

ASKER

Sorry, this doesn't work.
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.
EE.xlsm
Fabrice:

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.

EEH
ASKER CERTIFIED SOLUTION
Avatar of Fabrice Lambert
Fabrice Lambert
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Fabrice -- thank you so, much... this solution works great!!!   I appreciate your assistance/help.  :)