I have two non-contiguous ranges which contain one common value. I want to use the intersection method to trigger a macro but this code does not do it. Any help please
Sheet7.Activate
With Sheets("Sheet7")
Set xrange = Sheets("sheet7").Range("A7:A9")
Set xcells = Sheets("sheet7").Range("Z8:Z10")
End With
For Each cell In xrange
If Not Application.Intersect(cell, xcells) Is Nothing Then
MsgBox "Hello"
End If
Next
Sheet7.Activate
With Sheets("Sheet7")
Set xrange = Sheets("sheet7").Range("A7:A9")
Set xcells = Sheets("sheet7").Range("Z8:Z10")
End With
For Each cell In xrange
If Not Application.Intersect(cell, xcells) Is Nothing Then
MsgBox "Hello"
End If
Next