0

I have multiple cell names already created in excel. I want to add prefix to each of these names based on what sheet they are in. I'm currently using this VBA code to do so:

 Sub RenameCells() Dim n As Name For Each n In Sheet1.Names n.Name = "NLOC1_" & n.Name Next n End Sub 

However, it does not seem to actually change the names in the sheet. I get no errors so I'm not sure what is wrong and why nothing is changing.

2

1 Answer 1

1

The names seem to be at Workbook level, so you need to use:

Sub RenameCells() Dim n As Name For Each n In ActiveWorkbook.Names n.Name = n.RefersToRange.Worksheet.Name & "_" & n.Name Next n End Sub 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.