Intersect Range Name - return range name

Ziggy12

Active Member
Joined
Jun 26, 2002
Messages
365
How do I find out which of the two ranges the target is in?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim IPJumpRange As Range
Dim OPJumpRange As Range

Set IPJumpRange = Range("B5:B14")
Set OPJumpRange = Range("B19:B28")

If Application.Sum(Range(Target.Offset(0, 1), Target.Offset(0, 14))) = 0 Then
Response = MsgBox("No volume data to drilldown on", vbOKOnly, "Select Drilldown")
Exit Sub
End If

If Intersect(Target, Union(IPJumpRange, OPJumpRange)) Is Nothing Then Exit Sub
SelectedSite = Target.Value

//I need to ID which range the target is in - the IP or OP JumpRange//

UpdatePgeFlds
End Sub

ziggy
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Re: Intersect Range Name - return range name. Is active cell in range

Add a function
Function InRange(IPJumpRange As Range, OPJumpRange As Range) As Boolean
Dim InterSectRange As Range
Set InterSectRange = Application.Intersect(IPJumpRange, OPJumpRange)
InRange = Not InterSectRange Is Nothing
Set InterSectRange = Nothing
End Function

then a bit of code to call it
If InRange(ActiveCell, Range("B5:B14")) Then JumpTo = "IP"
If InRange(ActiveCell, Range("B19:B28")) Then JumpTo = "OP"

Maybe asking the question prompts a thought a bout the answer.
 
Upvote 0
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim IPJumpRange As Range
    Dim OPJumpRange As Range

    Set IPJumpRange = Range("B5:B14")
    Set OPJumpRange = Range("B19:B28")

    If Application.Sum(Range(Target.Offset(0, 1), Target.Offset(0, 14))) = 0 Then
        Response = MsgBox("No volume data to drilldown on", vbOKOnly, "Select Drilldown")
        Exit Sub
    End If

    If Intersect(Target, Union(IPJumpRange, OPJumpRange)) Is Nothing Then Exit Sub
    SelectedSite = Target.Value

    [COLOR="Green"]'//I need to ID which range the target is in - the IP or OP JumpRange//[/COLOR]
[COLOR="Red"]    If Target.Row < 15 Then
        [COLOR="Green"]' Target is in IP[/COLOR]
    Else
       [COLOR="Green"] ' Target is in OP[/COLOR]
    End If[/COLOR]

    UpdatePgeFlds
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,570
Messages
6,179,610
Members
452,931
Latest member
The Monk

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