Check if a range is inside another

  • Thread starter Thread starter Rafael Sobral
  • Start date Start date
R

Rafael Sobral

Hi,

What options do I have to check if the target range of a
SelectionChange event is inside another?


Rafael
 
Hi Rafael
This will give you a start
;-)

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Target, Range("myrng")) Is Nothing Then
MsgBox "ranges intersect"
Else
MsgBox "Ranges Don't intersect!"
End If
End Sub
 
Loomah showed how to check if they intersect by at least one cell although I
would assume contain means that all cells in target are within the range of
myrng . To see if target is totally contained in the range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Application.Union(Target, Range("myrng")).Address =
Range("myrng").Address Then
MsgBox "Target is contained within or equal to myrng"
Else
MsgBox "Target not contained within or equal to myrng"
End If
End Sub

you can use Intersect and compare the address to Target.address
 
Back
Top