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:
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:
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?
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?