SOLVED
Home

Taking worksheet names from cells in another worksheet

%3CLINGO-SUB%20id%3D%22lingo-sub-866983%22%20slang%3D%22en-US%22%3ETaking%20worksheet%20names%20from%20cells%20in%20another%20worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-866983%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20work%20book%20with%20numerous%20worksheets%20and%20I%20want%20the%20names%20of%20worksheets%20to%20automatically%20update%20based%20on%20changes%20to%20certain%20cells%20in%20the%201st%20worksheet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%20column%20A%20in%20worksheet%201%20(which%20is%20called%20training%20matrix)%20has%20names%20of%20people.%20I%20want%20the%20subsequent%20sheets%20to%20take%20their%20names%20from%20Column%20A%20in%20worksheet%201%20so%20if%20the%20name%20changes%20in%20that%20it%20will%20automatically%20update%20the%20name%20of%20the%20worksheet%20it%20relates%20to.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20this%20possible%3F%3C%2FP%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-866983%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-867044%22%20slang%3D%22en-US%22%3ERe%3A%20Taking%20worksheet%20names%20from%20cells%20in%20another%20worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-867044%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F412366%22%20target%3D%22_blank%22%3E%40jkpanic%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20Sheet%20called%20%22Training%20Matrix%22%20in%20the%20attached%20contains%20the%20following%20Change%20Event%20code%20on%20its%20Module.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%0AIf%20Target.CountLarge%20%26gt%3B%201%20Then%20Exit%20Sub%0ADim%20ws%20As%20Worksheet%0ADim%20Cel%20As%20Range%0ADim%20i%20As%20Long%0A%0AOn%20Error%20GoTo%20Skip%0AIf%20Not%20Intersect(Target%2C%20Range(%22SheetNames%22))%20Is%20Nothing%20Then%0A%20%20%20%20Application.EnableEvents%20%3D%20False%0A%20%20%20%20If%20Target%20%26lt%3B%26gt%3B%20%22%22%20Then%0A%20%20%20%20%20%20%20%20i%20%3D%20Application.Match(Target.Value%2C%20Range(%22SheetNames%22)%2C%200)%0A%20%20%20%20%20%20%20%20i%20%3D%20i%20%2B%201%0A%20%20%20%20%20%20%20%20On%20Error%20Resume%20Next%0A%20%20%20%20%20%20%20%20Set%20ws%20%3D%20Worksheets(i)%0A%20%20%20%20%20%20%20%20On%20Error%20GoTo%200%0A%20%20%20%20%20%20%20%20On%20Error%20GoTo%20Skip%0A%20%20%20%20%20%20%20%20If%20Not%20ws%20Is%20Nothing%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20Worksheets(i).Name%20%3D%20Target.Value%0A%20%20%20%20%20%20%20%20Else%0A%20%20%20%20%20%20%20%20%20%20%20%20Set%20ws%20%3D%20Worksheets.Add(after%3A%3DWorksheets(i%20-%201))%0A%20%20%20%20%20%20%20%20%20%20%20%20ws.Name%20%3D%20Target.Value%0A%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20End%20If%0AEnd%20If%0AApplication.EnableEvents%20%3D%20True%0AExit%20Sub%0ASkip%3A%0AApplication.Undo%0AApplication.EnableEvents%20%3D%20True%0AMsgBox%20Err.Description%2C%20vbExclamation%2C%20Err.Number%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EThe%20sheets%20as%20per%20the%20names%20in%20A2%3AA11%20which%20is%20a%20Named%20Range%20called%20%22SheetNames%22%20already%20exist%20in%20the%20file%20and%20if%20you%20change%20any%20name%20in%20A2%3AA11%2C%20the%20corresponding%20Sheet%20will%20also%20be%20renamed.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESee%20if%20this%20is%20what%20you%20were%20trying%20to%20achieve.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-867066%22%20slang%3D%22en-US%22%3ERe%3A%20Taking%20worksheet%20names%20from%20cells%20in%20another%20worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-867066%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20this%20is%20exactly%20what%20I'm%20looking%20for%20but%20do%20not%20understand%20how%20you%20got%20to%20that.%20Do%20not%20know%20where%20the%20%22Module%22%20is%20or%20how%20to%20put%20the%20change%20event%20code%20in.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWould%20appreciate%20some%20tuition.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJK%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-867146%22%20slang%3D%22en-US%22%3ERe%3A%20Taking%20worksheet%20names%20from%20cells%20in%20another%20worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-867146%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F412366%22%20target%3D%22_blank%22%3E%40jkpanic%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20implement%20the%20code%20to%20your%20workbook%2C%20follow%20these%20steps...%3C%2FP%3E%3COL%3E%3CLI%3ESelect%20the%20Names%20in%20column%20A%20and%20click%20in%20the%20Name%20Box%20(left%20to%20Formula%20bar%20where%20you%20see%20the%20cell%20address)%20and%20type%20SheetNames%20so%20that%20the%20selected%20range%20will%20be%20treated%20as%20a%20Named%20Range%20called%20SheetNames.%20Refer%20the%20image%20at%20the%20bottom%20to%20get%20some%20visual%20clue.%3C%2FLI%3E%3CLI%3EMake%20sure%20for%20all%20the%20names%20in%20the%20Named%20Range%20SheetNames%2C%20there%20are%20corresponding%20Sheets%20in%20the%20file%20in%20the%20same%20sequence%20as%20Names%20in%20column%20A.%3C%2FLI%3E%3CLI%3EWhen%20you%20have%20the%20above%20setup%2C%20right%20click%20on%20Sheet%20Tab%20Training%20Matrix%20(the%20sheet%20which%20contains%20the%20Names%20in%20column%20A%20as%20discussed%20in%20above%20two%20steps)%20--%26gt%3B%20View%20Code%20and%20copy%20the%20code%20from%20above%20post%20and%20paste%20into%20the%20opened%20code%20window%20which%20appears%20after%20clicking%20on%20View%20Code.%3C%2FLI%3E%3CLI%3ESave%20your%20workbook%20as%20Macro-Enabled%20Workbook.%3C%2FLI%3E%3C%2FOL%3E%3CP%3EAnd%20you%20are%20all%20set%20to%20test%20the%20code%20now.%3C%2FP%3E%3CP%3ELet%20me%20know%20if%20you%20have%20still%20any%20doubt%20in%20implementing%20this%20code%20to%20your%20original%20workbook.%3C%2FP%3E%3CP%3E%3CSTRONG%3EVisual%20clue%20for%20Step1.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20789px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F132767i7C8A3656CC15CD41%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22NamedRange.jpg%22%20title%3D%22NamedRange.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EVisual%20clue%20for%20Step3.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20539px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F132768i48C31D4633DBBE5E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22SheetModule.jpg%22%20title%3D%22SheetModule.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20that%20takes%20care%20of%20your%20original%20question%2C%20please%20don't%20forget%20to%20accept%20the%20post%20with%20the%20proposed%20solution%20to%20accept%20as%20a%20Best%20Answer%2FResponse%20to%20mark%20your%20question%20as%20Solved.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-867182%22%20slang%3D%22en-US%22%3ERe%3A%20Taking%20worksheet%20names%20from%20cells%20in%20another%20worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-867182%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%20it%20works%20but%20I%20have%20one%20that%20won't%20change.%20I%20have%20attached%20the%20file%20and%20names%201%20to%203%20change%20on%20the%20tabs%20for%20the%20following%20worksheets%20but%20the%204th%20name%20(row6)%20doesn't%20change%20the%20corresponding%20tab%20but%205th%20name%20(row7)%20changes%20the%20tab%20for%20the%204th%20name%3F%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-867357%22%20slang%3D%22en-US%22%3ERe%3A%20Taking%20worksheet%20names%20from%20cells%20in%20another%20worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-867357%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F412366%22%20target%3D%22_blank%22%3E%40jkpanic%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20find%20the%20attached.%20I%20have%20tweaked%20the%20existing%20code%20and%20added%20a%20new%20code%20as%20I%20changed%20the%20approach%20to%20rename%20the%20sheets.%3C%2FP%3E%3CP%3EIf%20you%20change%20a%20name%20in%20column%20A%20and%20if%20sheet%20for%20the%20name%20which%20you%20changed%20doesn't%20exist%20in%20the%20file%2C%20a%20message%20will%20be%20popped%20up%20informing%20you%20that%20a%20sheet%20doesn't%20exist%20yet%20for%20the%20name%20you%20changed.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-869718%22%20slang%3D%22en-US%22%3ERe%3A%20Taking%20worksheet%20names%20from%20cells%20in%20another%20worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-869718%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Subodh%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20sorry%20to%20be%20a%20pain%20but%20the%20changes%20you%20made%20do%20not%20work%20as%20when%20I%20type%20in%20a%20name%20now%20instead%20of%20changing%20the%20name%20on%20the%20subsequent%20worksheet%20it%20just%20comes%20up%20with%20the%20dialog%20box%20saying%20worksheet%20name%20does%20not%20exist%20insert%20worksheet%20with%20that%20name%20which%20defeats%20the%20object%20of%20what%20we're%20trying%20to%20do.%20The%20fist%20code%20worked%20better%20except%20for%20missing%20that%20one%20row%20out%20of%20the%20range.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20do%20I%20revert%20back%20to%20that%20but%20fix%20the%20row%20to%20worksheet%20glitch%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJulian%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-869801%22%20slang%3D%22en-US%22%3ERe%3A%20Taking%20worksheet%20names%20from%20cells%20in%20another%20worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-869801%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F412366%22%20target%3D%22_blank%22%3E%40jkpanic%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20confirming%20through%20PM%20that%20everything%20is%20working%20as%20desired.%20%3Athumbs_up%3A%3C%2FP%3E%3C%2FLINGO-BODY%3E
jkpanic
Occasional Contributor

I have a work book with numerous worksheets and I want the names of worksheets to automatically update based on changes to certain cells in the 1st worksheet.

 

For example column A in worksheet 1 (which is called training matrix) has names of people. I want the subsequent sheets to take their names from Column A in worksheet 1 so if the name changes in that it will automatically update the name of the worksheet it relates to.

 

Is this possible?

 
7 Replies

@jkpanic 

The Sheet called "Training Matrix" in the attached contains the following Change Event code on its Module.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
Dim ws As Worksheet
Dim Cel As Range
Dim i As Long

On Error GoTo Skip
If Not Intersect(Target, Range("SheetNames")) Is Nothing Then
    Application.EnableEvents = False
    If Target <> "" Then
        i = Application.Match(Target.Value, Range("SheetNames"), 0)
        i = i + 1
        On Error Resume Next
        Set ws = Worksheets(i)
        On Error GoTo 0
        On Error GoTo Skip
        If Not ws Is Nothing Then
            Worksheets(i).Name = Target.Value
        Else
            Set ws = Worksheets.Add(after:=Worksheets(i - 1))
            ws.Name = Target.Value
        End If
    End If
End If
Application.EnableEvents = True
Exit Sub
Skip:
Application.Undo
Application.EnableEvents = True
MsgBox Err.Description, vbExclamation, Err.Number
End Sub

The sheets as per the names in A2:A11 which is a Named Range called "SheetNames" already exist in the file and if you change any name in A2:A11, the corresponding Sheet will also be renamed.

 

See if this is what you were trying to achieve.

 

 

 

 

@Subodh_Tiwari_sktneer 

Hi this is exactly what I'm looking for but do not understand how you got to that. Do not know where the "Module" is or how to put the change event code in.

 

Would appreciate some tuition.

 

Cheers

 

JK

Solution

@jkpanic 

To implement the code to your workbook, follow these steps...

  1. Select the Names in column A and click in the Name Box (left to Formula bar where you see the cell address) and type SheetNames so that the selected range will be treated as a Named Range called SheetNames. Refer the image at the bottom to get some visual clue.
  2. Make sure for all the names in the Named Range SheetNames, there are corresponding Sheets in the file in the same sequence as Names in column A.
  3. When you have the above setup, right click on Sheet Tab Training Matrix (the sheet which contains the Names in column A as discussed in above two steps) --> View Code and copy the code from above post and paste into the opened code window which appears after clicking on View Code.
  4. Save your workbook as Macro-Enabled Workbook.

And you are all set to test the code now.

Let me know if you have still any doubt in implementing this code to your original workbook.

Visual clue for Step1.

NamedRange.jpg

 

Visual clue for Step3.

SheetModule.jpg

 

If that takes care of your original question, please don't forget to accept the post with the proposed solution to accept as a Best Answer/Response to mark your question as Solved.

@Subodh_Tiwari_sktneer 

Cheers it works but I have one that won't change. I have attached the file and names 1 to 3 change on the tabs for the following worksheets but the 4th name (row6) doesn't change the corresponding tab but 5th name (row7) changes the tab for the 4th name??

 

Cheers

@jkpanic 

Please find the attached. I have tweaked the existing code and added a new code as I changed the approach to rename the sheets.

If you change a name in column A and if sheet for the name which you changed doesn't exist in the file, a message will be popped up informing you that a sheet doesn't exist yet for the name you changed.

 

 

@Subodh_Tiwari_sktneer 

 

Hi Subodh,

 

I am sorry to be a pain but the changes you made do not work as when I type in a name now instead of changing the name on the subsequent worksheet it just comes up with the dialog box saying worksheet name does not exist insert worksheet with that name which defeats the object of what we're trying to do. The fist code worked better except for missing that one row out of the range.

 

How do I revert back to that but fix the row to worksheet glitch?

 

Cheers

 

Julian

@jkpanic 

Thanks for confirming through PM that everything is working as desired.

Related Conversations
flashing a white screen while open new tab
cntvertex in Discussions on
13 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
22 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
Edge insider Dev bypasses IE mode website list
HotCakeX in Enterprise on
4 Replies