#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
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").Range Set colC = ListObjects("Table1").ListColumns("c").Range ''' Dim rng As Range Set rng = Union(colA,colC) If intersect(ActiveCell, rng) Is Nothing Then MsgBox "not intersect" Else MsgBox "intersect" End If End Sub |
Thread Tools | |
Display Modes | |
|