Hello,
I am attempting to execute a macro when any cell within a given two ranges are selected. The private sub works fine when I'm just doing it for A2:A100, but attempting to add range C2:C100 breaks it. How do I properly capture multiple ranges here? Do I use an "Or" statement or some other approach?
Thank you
I am attempting to execute a macro when any cell within a given two ranges are selected. The private sub works fine when I'm just doing it for A2:A100, but attempting to add range C2:C100 breaks it. How do I properly capture multiple ranges here? Do I use an "Or" statement or some other approach?
Thank you
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const WS_RANGE As String = "A2:A100" Or "C2:C100"
On Error GoTo ws_exit
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Call 'My Macro Here
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub