selecting named ranges that include particular text

keithmct

Active Member
Joined
Mar 9, 2007
Messages
256
Office Version
  1. 2021
Platform
  1. Windows
I want to select multiple price grids so as to increase them by a few percent if needed. They are all named ranges and all end in "prices". Can I do something in a macro like:
Range(*&"prices").Select ?
 
some of my named ranges with "prices" in their name are no longer used and I wanted to move them to a new worksheet that I can hide
Union method works only if name ranges are in a single sheet.
If they are no longer used why not just delete them?
 
Upvote 1

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
If they are no longer used why not just delete them?
because you never know? just in case? it was a lot of work originally and it seems a waste to delete?
I'll move them and just remove the named ranges instead. thanks for the answer though.
 
Upvote 0
Well, there's a way to do it. Let's say the sheet name where you want to process the name ranges is "Sheet1", you can alter your code like this:
Rich (BB code):
Sub Test2()
Dim nm
Dim c As Range

For Each nm In ActiveWorkbook.Names
    If nm.Name Like "*prices" Then
        If Range(nm.Name).Parent.Name = "Sheet1" Then
    '        Debug.Print nm.Name
            If c Is Nothing Then
               Set c = Range(nm.Name)
            Else
               Set c = Union(c, Range(nm.Name))
            End If
        End If
    End If
Next nm

'now, c is holding all those named ranges.
If Not c Is Nothing Then
c.Select
Else
MsgBox "Can't find names that end with 'prices'"
End If

End Sub
So, basically the code says, get me all the name ranges with "prices" in the end and they refer to range in Sheet1.
 
Upvote 0

Forum statistics

Threads
1,223,627
Messages
6,173,424
Members
452,515
Latest member
Alicedonald9

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