I'm trying to change the address that a named range refers to. There are two ranges in the workbook with the same name, one scoped to the workbook and the other scoped to SheetA
. I'm using this code:
Sub changeNamedRangeAddress(bk As Workbook, rangeName As String, newRange As Range)
bk.Names(rangeName).RefersTo = newRange
End Sub
When I look at the value for bk.Names(rangeName)
in the Immediate window, it appears to be referencing the global version of that name, because the following returns true:
?typeof bk.Names(rangeName).Parent is Workbook
But after the sub runs, the locally scoped version's address has changed to that of newRange.address
and the global one remains the same.
Is there anything else I can do to make sure that .RefersTo
targets the global named range?
EDIT: The sheet that the locally scoped named range refers to is active when this script runs.