Hi Guys,
is there a function to return the name of a named range (if it exists) of the Target.Address?
Regards
Hi Guys,
is there a function to return the name of a named range (if it exists) of the Target.Address?
Regards
Hello jordan2322,
No there is not. But one could be written using VBA.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Something like this?
How would i modify this such that the target.address only needs to be within the named range - not match the named range address exactly.
As the named ranges are more than a single cell this (as written in the code below) would be impossible as the user can only double click a single cell not a range.
(note: I want this to be called using the double click event)
![]()
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) If Target.Address = Range("Fruit").Address Then MsgBox (Target.Address) End If End Sub
Try this
![]()
Dim oneName As Name Dim foundName As Name For Each oneName In ThisWorkbook.Names On Error Resume Next If oneName.RefersToRange Is Nothing Then On Error GoTo 0 Rem name is not range Else On Error GoTo 0 If oneName.RefersToRange.Parent.Name = Target.Parent.Name Then If Not Application.Intersect(Target, oneName.RefersToRange) Is Nothing Then Set foundName = oneName End If End If End If Next oneName If foundName Is Nothing Then MsgBox "not inside a named range" Else MsgBox "target is inside named range, " & foundName.Name End If
_
...How to Cross-post politely...
..Wrap code by selecting the code and clicking the # or read this. Thank you.
Solved using the above. Thank you Mikerickson for your reply!![]()
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Dim nName As Name For Each nName In ThisWorkbook.Names If Not Intersect(Range(nName.Name), Target) Is Nothing Then Cancel = True MsgBox (nName.Name) Exit For End If Next nName End Sub
What happens if the cell you click on is in more than one named range? Do you want all named ranges that contain the double clicked cell to appear?
One test is worth a thousand opinions.
Click the * Add Reputation below to say thanks.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks