Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA for Excel - How to check intersection of ranges are not empty

Tags:

excel

vba

I have two questions: 1) How do I check if the intersection or a range is not empty? For example if I want to check if its empty I write for example

if application.intersect(r1,r2) is nothing

but is there something that is negation of nothing? not nothing didn't work for example.

2) How can I compate ranges? For example I have ranges r1,r2,r3 and I want to check if the intersection of r1 and r2 is r3. Two thing that I have tried and didn't work:

1 - application.intersect(r1,r2) = r3
2 - application.intersect(r1,r2) is r3

Would appreciate any help that I can get, Thanks!

like image 448
mathstackuser123 Avatar asked Dec 12 '25 13:12

mathstackuser123


1 Answers

To see if the intersection of two ranges is a third range:

Set intRng =  Intersect(R1, R2)
If Not intRng Is Nothing then
    Set intRng =  Intersect(intRng, R3)
    If Not Intersect(intRng) Is Nothing
        If intRng.Address = R3.Address Then MsgBox "intersection of ranges R1 and R2 is range R3"
    End If
End If
like image 58
user3598756 Avatar answered Dec 15 '25 04:12

user3598756



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!