Is there a function that will return the name of a range?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,687
Office Version
  1. 365
Platform
  1. Windows
Say B5 has been assigned the name "SalesDate". Is there a function (=getname(B5)) that will return the name ("SalesDate")?
 
This worked for me :
VBA Code:
Function GetRangeName(ByVal Rng As Range, Optional ByVal FullName As Boolean = False) As String

    Dim sName As String
    On Error Resume Next
   
    sName = Rng.Name.Name
    GetRangeName = IIf(FullName, sName, Right(sName, Len(sName) - InStrRev(sName, "!")))

End Function

This works if the Rng has a name, but it gets a Value error if not.

GetRangeName.xlsx
CDE
5NameCell AddressRange Name
6Name is: AAA
7Name is: NextNameNextNameNextName
8Name is: #VALUE!#VALUE!
Sheet1
Cell Formulas
RangeFormula
D6:D8D6=GetRangeName(C6)
E6E6=GetRangeName(A)
E7E7=GetRangeName(NextName)
E8E8=GetRangeName(C8)
Named Ranges
NameRefers ToCells
A=Sheet1!$C$6D6:E6
NextName=Sheet1!$C$7D7:E7
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I have been working on this code on and off for several months. I now have a UDF that I think will return the name of passed ranges including those that it is part of. It will also differentiate between local and global names. It is about 100 lines of code.

Is anyone interested in it?

If so, should I post it here or in a new thread? I already mistakenly started two threads about this topic, so I am reluctant to start another one unless that is the best option. If I post it here, should I unmark the previous answer and wait for any comments on the new code? That would be one reason to start a new thread.
 
Upvote 0
Personally I would post it as an article as it isn't now a question
Instructions below

I would also report the duplicate thread using the report icon (bottom left of any post) explaining what happened and a Moderator will probably lock it.

Hopefully a Moderator will read this thread and offer some more official advice
 
Upvote 0
Personally I would post it as an article as it isn't now a question
I was hoping to get some feedback on the code. I have gotten such good feedback in the past. And there are 2-3 enhancements I plan to make when I get the time.

I would also report the duplicate thread using the report icon (bottom left of any post) explaining what happened and a Moderator will probably lock it.
Done

Hopefully a Moderator will read this thread and offer some more official advice
Ok
 
Upvote 0
I was hoping to get some feedback on the code.
Normally I would post it is the General discussion forum if wanting feedback on code, but in case I would wait for a Moderator to respond because of the multiple threads. Sorry I know that isn't much help.
 
Upvote 0
Normally I would post it is the General discussion forum if wanting feedback on code, but in case I would wait for a Moderator to respond because of the multiple threads. Sorry I know that isn't much help.
It's fine. I already messed up once, so I have no problem waiting for guidance from on high! 🙃😉 I thought it would fit nicely here since it addresses the original question. The new code is kinda cool, if I do say so myself. 😄

I thought the General Discussion section was for things other than Excel or Access.
 
Upvote 0
I thought the General Discussion section was for things other than Excel or Access.
It's for General discussion, including any questions about programs other than Excel / Access / Power BI / Power Query / Other Languages.
If it Excel related but not a question then that is the normal place to post it (which is why I stated to wait for a Moderator as I am not sure if it would be treated as a question or not, as you want the code reviewed then it probably is)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,965
Messages
6,175,660
Members
452,666
Latest member
AllexDee

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