VBA Code to Rename a Defined Range

azbasketcat

New Member
Joined
Feb 20, 2010
Messages
30
I am trying to find a way to use VBA to change the name of a Defined Range.

Everything I have found so far creates a new range and then deletes the old range. I have used the existing named ranges throughout a large workbook, so I don't want to delete the existing named ranges.

Also, I have the names of the ranges I want to rename (a subset of all the named ranges in the workbook) in a range called "ExistingNames" and then I have another named range called "NewNames" which has the new name. My hope is to have the macro loop through ExistingNames and for each range assign the new name.

Any suggestions would be greatly appreciated. Thanks
 
Im trying to use your macro to change my named ranges names in the Name Manager.

Created a list, 2 columns and named that range as NameList.
Column A = Current Named Ranges Names
Column B = New Named Ranges Names

Changed code to reference Sheet10, thats where my list is.
Ran Macro, No changes in the Name Manager.

No error or compile messages. Mouse icon changes to the hour glass for a few seconds and returns to normal.

Any idea what I might be doing wrong?
Post the exact macro you are running and tell us where it is installed, standard module in the active workbook, or sheet module or …? What is the range the list in sheet10, occupies ? Is the macro run from sheet10?
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Post the exact macro you are running and tell us where it is installed, standard module in the active workbook, or sheet module or …? What is the range the list in sheet10, occupies ? Is the macro run from sheet10?
VBA Code:
Sub NameChanger()
    Dim arNames()
    Dim nm As Name
    Dim i As Integer
    
    arNames = Sheets("Sheet10").Range("NameList").Value
    For i = LBound(arNames) To UBound(arNames)
        For Each nm In ActiveWorkbook.Names
            If nm.Name = arNames(i, 1) Then
                nm.Name = arNames(i, 2)
            End If
        Next nm
    Next i
End Sub

This macro is placed under Modules\ Module 1 (not a class-module)

List range is A1 to B807

When running the macro i have sheet10 open,
running macro by going to Developer Tab \ Macro and selecting NameChanger
 
Upvote 0
I should have looked through this old thread before I replied to you. I have no access to a computer right now. Read through this thread carefully and try Jerry Sullivan’s code that returns a message if there is a problem with nothing happening.
 
Upvote 0
I should have looked through this old thread before I replied to you. I have no access to a computer right now. Read through this thread carefully and try Jerry Sullivan’s code that returns a message if there is a problem with nothing happening.
i did that as well and there is actually 3 different versions of the code. Tried all 3, no errors, and names still not updated.
 
Upvote 0
Any formulas that use existing names (see post #14)?
 
Upvote 0
Is there a simple formula to have a cell's value be equal to its Named Range? (I am only using range names that are 1 cell large)

for example =RangeName

BTW, these macros works so well, thank you to everyone on this thread. Now I am trying to figure out a way to extract my range names easily.
:)
 
Upvote 0

Forum statistics

Threads
1,215,374
Messages
6,124,573
Members
449,173
Latest member
Kon123

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