Change sheet codename to match sheet name

GeeWhiz7

Board Regular
Joined
Nov 22, 2021
Messages
214
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi there,
I am currently running VBA that creates new worksheets based on a list of names in a starting worksheet.
All that works, but I notice when i update the names and rerun the code, the sheet names are correct, but the CodeNames keep going incrementally higher and higher.

The part of the code that I can't make work is below.
If I remove the ThisWorkbook.VBProject.VBComponents(Sheets("nameCatch").CodeName).Name = nameCatch it works fine in making new sheets with the correct sheet name, but the codenames keep going up and up and I want to be able to reference the codename as the sheetname.

Its something about the syntax of the removed line that is tripping me up.

Thanks for the help!
-Will

You can see I'm on worksheet 437 when I would like this to always be equal to the regular sheet name.
1638653089249.png


Snippet...

'Loop through all names
For name = firstnameRow To lastRow

nameCatch = Worksheets("Inputs").Range("$a$" & name)

If nameCatch = "" Then
GoTo NextIteration
End If

'Create a sheet for each name in input list
'***************************************************
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = nameCatch
ThisWorkbook.VBProject.VBComponents(Sheets("nameCatch").CodeName).Name = nameCatch

...
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Should be nameCatch, not "nameCatch"

VBA Code:
ActiveSheet.Name = namecatch
ThisWorkbook.VBProject.VBComponents(Sheets(namecatch).CodeName).Name = namecatch
 
Upvote 0
Good catch riv01, pun intended. I made the change and CodeNames were correctly changing up to a point so thank you for spotting that!

I also didn't realize I had a special character in one of the names (é) and VB was breaking on changing the CodeName when encountering it.
Using replace helps and it is working.

Thanks
 
Upvote 0

Forum statistics

Threads
1,215,847
Messages
6,127,270
Members
449,372
Latest member
charlottedv

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