A range has several names: how to find these names? vba

lalbatros

Well-known Member
Joined
Sep 5, 2007
Messages
659
Hello,

I have a lot of ranges who have two names.

The first name is provided automatically by excel (query tables).
I cannot control this first name correctly.
The second name is defined by my application.

I would like to find a way to retrieve (in vba) the second name of such a given range.
Looping through all names definitions to find a match might be possible.
However, I fear this might not be reliable, and this might be also complicated.

Would you know of an easy and reliable way to find out all the names given to a range?

Thanks a lot,

Michel
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Here is a simple loop over the Names collection. I use this to delete named ranges that refer to external locations by looking for a square bracket in the RefersTo property. Similarly, you could search for all or part of the address.


Sub deleteInvalidNamedRanges()
'Deletes named ranges that refer to an external file
Dim n As Name
For Each n In Names
If InStr(1, n.RefersTo, "[") <> 0 Then
Debug.Print n.RefersTo & " - " & n.Name
n.Delete
End If
Next n
Set n = nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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