Question

I'm looking for the best way to code in multiple ranges for my double click event.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A3:A25")) Is Nothing Then
    'code
End If
End Sub

As you see above, when A3 to A25 is clicked, the double click event takes place. But I also have other sections throughout the sheet that I want to include to set off the event. A29:A40, F3:F37, K3:K40, P3:P40.

What is the best way to code that without adding new 'If' blocks?
Or is adding the new 'If' blocks (and calling a subroutine) the best way?

Was it helpful?

Solution

Use this one:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Target, Range("A3:A25, A29:A40, F3:F37, K3:K40, P3:P40")) Is Nothing Then
        'code
    End If
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top