Need smarter solution to get the name of a name...

Mexcel

New Member
Joined
Sep 3, 2009
Messages
12
In a worksheet cell I want =NameOf(MyRangeName) to produce a string that is "MyRangeName". (While MyRangeName is a defined name that refers to e.g. =Sheet1!A1)

This works:
Code:
Function NameOf(Myname)
For Each N In ThisWorkbook.Names
If N.RefersTo = Myname.Name Then
  NameOf = N.Name
  Exit Function
End If
Next
End Function

But can become a bit slow if this function gets used a lot and there are a lot of names in the workbook. Is there a smarter way to do this without looping through all names like:

Code:
Function NameOf(Myname As Object)
NameOf = Myname.Name
End Function

This produces "=Sheet1!A1" rather than "MyRangeName"
Myname.Value produces the value in A1. I.e. this does not yet work. Anyone have a bright idea?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,214,528
Messages
6,120,065
Members
448,942
Latest member
sharmarick

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