For Each in range name sheets with codename

rsjury

New Member
Joined
Jun 28, 2014
Messages
48
Looking to use a Range from sheet "Employee List" ("A2:A33") and name only sheets with the beginning codename "FTE*".

CodenameCellRangeResult
FTE01 (FTE01)A2ToddFTE01 (Todd)
FTE02 (FTE02)A3SteveFTE02 (Steve)
Table (Table)Not Renamed
FTE03 (FTE03)A4MarkFTE03 (Mark)
Report (Report)Not Renamed

<tbody>
</tbody>

I know I need to use "For Each in range" and "if FTESheet.Codename like "FTE*" Then". But not sure how to loop through the Range and the Sheets at the same time.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Is this what you're after
Code:
Sub renamesht()

    Dim ws As Worksheet
    
    For Each ws In Worksheets
        If ws.Name Like "FTE*" Then
            ws.Name = Sheets("Employee List").Range("A" & Right(ws.Name, 2) + 1)
        End If
    Next ws
        

End Sub
 
Upvote 0
Your question is not entirely clear, but assuming cells A2 downward contain sheet names (what are shown on the sheet tabs) and assuming you want the code name followed by the sheet name (in parentheses) in Column B but only if the code name starts with "FTE", then give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub GetCodeAndTabNames()
  Dim R As Long
  For R = 2 To Cells(Rows.Count, "A").End(xlUp).Row
    If Sheets(Cells(R, "A").Value).CodeName Like "FTE*" Then
      Cells(R, "B").Value = Sheets(Cells(R, "A").Value).CodeName & " (" & Cells(R, "A").Value & ")"
    End If
  Next
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Thank you both, this one almost gets me there

Here are my changes but I get a "type mismatch" once it gets to "WS.Name = Emp_List.Range

Sub renamesht()

Dim ws As Worksheet

For Each ws In Worksheets
If ws.CodeName Like "FTE*" Then
ws.Name = EMP_LIST.Range("A" & Right(ws.Name, 2) + 1)
End If
Next ws

End Sub

So what I am doing is using the Codename to find the sheet and then renaming the sheet name with the cells from "Emp_List" sheet. This way if I change a name it will go back to that sheet and rename it.

So the codename FTE01 Sheets name is "Todd" Because cell "A2" on EMP_List = Todd, If I change the name in "A2" to "TED", FTE01 Sheet name becomes "TED".

Thanks
 
Last edited:
Upvote 0
What is EMP_LIST?
a Sheet name, a sheet codename, or a range name
 
Upvote 0
What are the last 2 characters of ws.name when the error occurs?
It sounds as if they aren't numbers
 
Upvote 0
Run-Time Error 13
Type Mismatch
Fluff asked you for the last two characters of the worksheet's name when the error occurs... not the error message. When the error occurs, execute this in the VB editor's Immediate Window and post back exactly what gets printed...

Print "<" & Right(ws.Name, 2) & ">"
 
Last edited:
Upvote 0
Missed this
So the codename FTE01 Sheets name is "Todd" Because cell "A2" on EMP_List = Todd, If I change the name in "A2" to "TED", FTE01 Sheet name becomes "TED".
So I suspect that what you need is
Code:
Sub renamesht()

    Dim ws As Worksheet
    
    For Each ws In Worksheets
        If ws.CodeName Like "FTE*" Then
            ws.Name = Sheet7.Range("A" & Right[COLOR=#ff0000](ws.CodeName[/COLOR], 2) + 1)
        End If
    Next ws

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,981
Members
449,058
Latest member
oculus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top