Aaaaargh - Please help me with Intersect..!!

DanUK

New Member
Joined
Aug 27, 2008
Messages
42
Hi guys,

I really hope someone out there in VBA land is able to offer me some assistance with this...even if that is to say that I can't do what I want to !!

I'm writing a some VBA code that tests to see if two non contiguous ranges overlap. I'm using the Intersect method to test for this like so:

Code:
If Not Intersect(usedRange, wordRng) Is Nothing Then

Once I've established that I do indeed have over lapping ranges (and after a further test to ensure that the overlap range is no bigger than 1 cell...), I then want to test if the values of the two overlapping ranges are the same. I tried the following code:

Code:
strAdd = Intersect(usedRange, wordRng).Address
Debug.Print usedRange.Range(strAdd).Value, wordRng.Rang(strAdd).Value

Now the above code doesn't work. It is syntactically correct and the two ranges (usedRange & wordRng) can be referenced in this way BUT not using the return value of the Intersect method as this is outside of the two ranges!! Does this make sense???

Does anyone know how I can obtain the values of the overalap of the intersecting ranges??

Thanks in advance.

Dan
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
If the ranges are overlapping and the overlap is limited to just one cell, you only need that one cell--not that same cell for both ranges as they would be one and the same.

Code:
strAdd = Intersect(usedRange, wordRng).Address
Debug.Print Range(strAdd).Value
 
Upvote 0
Hi, maybe you are overthinking this one. Does this work:

Code:
Dim r As Range
Dim myVal as Variant
Set r = Intersect(UsedRange, wordRng)
If Not r Is Nothing Then     [COLOR="SeaGreen"]'//proceed if there is an overlap[/COLOR]
    If r.Count = 1 Then      [COLOR="seagreen"]'//proceed if overlap is one cell[/COLOR]
        myVal = r.Value
    End If
End If
 
Upvote 0
Thanks guys!

It was late last night when i was doing this and clearly i was suffering from brain rot!! Reading your replies made it obvious to me where i was going wrong. Only one real value here and not two...

Thanks again

Dan
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,846
Members
449,194
Latest member
HellScout

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