Change Range Names with VBA Macro.

dsorensen

New Member
Joined
Apr 3, 2014
Messages
7
I am trying to change some range names on different sheets so I can do this faster than doing it manually. I have about 30 ranges for each sheet and they are all named Prop___ i.e. Prop1, Prop2, PropLAE1, PropSUB1... and I want to change them to CovA___.
I need to do this for 5 different sheets so if there is a VBA script to do this with out having to name all of the ranges that would be great. I have excel 2013 professional if that changes anything.

Thanks in advance.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Welcome to the forum,

Give this ago
Sub ChangeName()
Dim Nam As Name
For Each Nam In ThisWorkbook.Names
Nam.Name = WorksheetFunction.Substitute(Nam.Name, "Prop", "CovA")
Next Nm
End Sub
 
Upvote 0
I think Trevor G meant to write this:

Code:
Sub ChangeName()
    Dim Nam As Name
    For Each Nam In ThisWorkbook.Names
        Nam.Name = WorksheetFunction.Substitute(Nam.Name, "Prop", "CovA")
    Next   Nam  
 End Sub
 
Upvote 0
Gavin,
I made the change to the For next statement when I tried this originally and it didn't work.
Thanks
 
Upvote 0
It's case sensitive so try to:

Replace:
Code:
Nam.Name = WorksheetFunction.Substitute(Nam.Name, "Prop", "CovA")

With:
Code:
Nam.Name = WorksheetFunction.Substitute(Nam.Name, "prop", "CovA")
 
Upvote 0
Nope still didn't work. The names are Prop___ so "Prop" should have worked if this code was going to work.
Any other ideas?
 
Upvote 0
The issue is that the names begin with Prop but then their is always something after it. I made a range and named it Prop and the macro worked and changed it to CovA. Is there a way to say if it starts with Prop change it from Prop to CovA reguardless of what comes after Prop?
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,979
Members
448,934
Latest member
audette89

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