I have a cell that has more than one named ranges associated with it. How do I get it to return a specific name without having to loop through all the names in the workbook?
Sub Test()
ActiveWorkbook.Names.Add Name:="AUserDefinedName1", RefersTo:="='Sheet1'!$A$1", Visible:=True
ActiveWorkbook.Names.Add Name:="AUserDefinedName2", RefersTo:="='Sheet1'!$A$1", Visible:=True
ActiveWorkbook.Names.Add Name:="MyName", RefersTo:="='Sheet1'!$A$1", Visible:=True
Dim n As Name
Set n = Range("A1").Name
Debug.Print n.Name
End Sub
If you run the above, for cell A1 it would only return the first name. However, how would I get it to return the other names associated with cell A1 as well or a specifically return 'MyName'?
I could loop through all names in the workbook and see if the 'RefersTo' property of the Name object matches the address for cell A1, but I would like a more direct solution if possible that's faster.
This thread gave a partial answer, but need what if there are more than one name? How do you get a Range to return its Name?