JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,687
- Office Version
- 365
- Platform
- 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
GetRangeName.xlsx | |||||
---|---|---|---|---|---|
C | D | E | |||
5 | Name | Cell Address | Range Name | ||
6 | Name is: A | A | A | ||
7 | Name is: NextName | NextName | NextName | ||
8 | Name is: | #VALUE! | #VALUE! | ||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
D6:D8 | D6 | =GetRangeName(C6) |
E6 | E6 | =GetRangeName(A) |
E7 | E7 | =GetRangeName(NextName) |
E8 | E8 | =GetRangeName(C8) |
Named Ranges | ||
---|---|---|
Name | Refers To | Cells |
A | =Sheet1!$C$6 | D6:E6 |
NextName | =Sheet1!$C$7 | D7:E7 |
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.Personally I would post it as an article as it isn't now a question
DoneI 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.
OkHopefully a Moderator will read this thread and offer some more official advice
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.I was hoping to get some feedback on the code.
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.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 for General discussion, including any questions about programs other than Excel / Access / Power BI / Power Query / Other Languages.I thought the General Discussion section was for things other than Excel or Access.