Thread: Intersect
View Single Post
 
Old 07-26-2014, 05:55 AM
tinfanide tinfanide is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default Intersect

A ListObject (Pivot Table):

a b c
1 2 3

ActiveCell = Cell B2 (value = "2")

The test Sub works (which returns "not intersect").
The test2 Sub does not work (which returns "intersect" but actually not).

I wonder how I can put more than 1 ranges in the arguments of the Intersect function.

Thank you.
P.S.: I have also attached the Excel file (intersect.xls).

Code:
Sub test()

If intersect(ActiveCell, Range("A:A,C:C")) Is Nothing Then
    MsgBox "not intersect"
Else
    MsgBox "intersect"
End If

End Sub

Sub test2()

Dim colA As ListColumn, colC As ListColumn
Set colA = ListObjects("Table1").ListColumns("a")
Set colC = ListObjects("Table1").ListColumns("c")

If intersect(ActiveCell, Range(colA.Range, colC.Range)) Is Nothing Then
    MsgBox "not intersect"
Else
    MsgBox "intersect"
End If

End Sub
Reply With Quote