How to find the range names that includes a Cell

kunal_shrivastava

New Member
Joined
Apr 19, 2011
Messages
32
Hello All,

Can we determine the range names that includes a cell??
Lets say i name a Range A1:C3 as "R_3_3_1"
Then i name a Range A1:A9 as "R_1_9_1"

Now can we determine from VBA that cell A1 is included in ranges "R_3_3_1" and "R_1_9_1"
and cell A8 is in only "R_1_9_1"
and cell C4 is not in any of the ranges..


Thanks in Advance
Kunal
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
You can return the name of a range like this:

Code:
MsgBox Range("A1:A3").Name.Name

but you have to use the entire range. To determine if a cell is within a range you can use the Intersect method:

Code:
MsgBox (Not Application.Intersect(Range("A1"), Names("R_3_3_1").RefersToRange) Is Nothing)
 
Upvote 0
To expand a bit, if you want a list of the cells that overlap in each range, you can use:

Code:
Public Sub NamedRangeIntersects()
Dim IntersectRNG            As Range, _
    rng                     As Range, _
    IntersectAddr           As String
    
Set IntersectRNG = Intersect(Range("R_3_3_1"), Range("R_1_9_1"))
If Not IntersectRNG Is Nothing Then
    For Each rng In IntersectRNG
        IntersectAddr = IntersectAddr & rng.Address(False, False) & ", "
    Next rng
    IntersectAddr = Left(IntersectAddr, Len(IntersectAddr) - 2)
End If
MsgBox IntersectAddr
End Sub
 
Upvote 0
Thanks All,
I got it....
Infact the below method that does my work...
Sub Find_Names()
For Each n In ActiveWorkbook.Names
Set y = Intersect(ActiveCell, Range(n.RefersTo))
If Not y Is Nothing Then MsgBox "Cell is in : " & n.Name
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,681
Members
452,937
Latest member
Bhg1984

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