If Not Intersect(Range1,Range2) Is Nothing Then
'they overlap at least partially
Else
'They don't overlap at all
End If
Sub test()
If Not Intersect(Range("A6:A10"), Range("A1:A20")) Is Nothing Then
MsgBox ("Range A6:A10 intersects Range A1:A20")
End If
If Intersect(Range("B8"), Range("A1:B4")) Is Nothing Then
MsgBox ("Range B8 does not intersects Range A1:B4")
End If
End Sub
Set rOverlap = Intersect(Range1,Range2)
If Not rOverlap Is Nothing Then 'ie is there some overlap?
If rOverlap.Count = Range1.Count Or rOverlap.Count = Range2.Count Then
'one range is fully contained within the second range
Else
'ranges only partially overlap
End If
Else
'Ranges don'toverlap at all
End If
If Intersect(r1, r2) Is Nothing Then
MsgBox "r1 and r2 do not intersect"
ElseIf r1.Address = r2.Address Then
MsgBox "r1 and r2 overlap completely"
ElseIf Intersect(r1, r2).Address = r2.Address Then
MsgBox "r2 is completely contained in r1"
ElseIf Intersect(r1, r2).Address = r1.Address Then
MsgBox "r1 is completely contained in r2"
ElseIf Not Intersect(r1, r2) Is Nothing Then
MsgBox "r1 and r2 intersect"
End If