I have code that will change the name of a named range. It works just fine if the named range does not appear in a formula anywhere in the workbook. But if it does appear, even in just one formula (and even in something as simple as something like =MyName), the code doesn't change the name. It doesn't cause an error, it just doesn't do what it's supposed to. It's as if it is simply ignoring the line of code.
The code:
oldName and newName are string variables, and I have confirmed the values of both are legit names. UnprotectEntireWorkbook, UnprotectAllSheets, ProtectAllSheets, and ProtectEntireWorkbook are all subs that do exactly what their names suggest.
So my workbook is unprotected and all of the sheets within the workbook are unprotected, yet the line nm.Name = newName does not do anything if the named range (oldName) appears in any cells in the workbook.
Does anyone have any idea why this would be happening?
The code:
VBA Code:
UnprotectEntireWorkbook
UnprotectAllSheets
Set nm = ThisWorkbook.Names(oldName)
nm.Name = newName
ProtectAllSheets
ProtectEntireWorkbook
oldName and newName are string variables, and I have confirmed the values of both are legit names. UnprotectEntireWorkbook, UnprotectAllSheets, ProtectAllSheets, and ProtectEntireWorkbook are all subs that do exactly what their names suggest.
So my workbook is unprotected and all of the sheets within the workbook are unprotected, yet the line nm.Name = newName does not do anything if the named range (oldName) appears in any cells in the workbook.
Does anyone have any idea why this would be happening?