I'm slowly getting more comfortable with VBA, but I frequently don't understand the logic in sample code that I find on the net. My present problem is understanding the event handling for a double click event.
The upper code is how I edited the sample code (which is commented out). Both
seem to function the same.
I understand the logic in my edited version, but not the logic in the sample:
If the intercept is Nothing, doesn't that mean that target cell is not within the designated range? So why the "Not"?
Why did the sample's author use the Not logic (I found a number of postings with this logic); does it have an advantage over my edited logic?
I'd sincerely appreciate any comments that you can offer.
Very respectfully,
Larry
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
' If the cell is not within the range B1:B10, then cancel
' If the cell is within the range, then act
If Application.Intersect(Target, Range("B1:B10")) Is Nothing Then
MsgBox ("is NOT in B1:B10") ' Action for out-of-range target
Cancel = True
Else: MsgBox ("is in B1:B10") ' Action if target is within the range
End If
' Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
' If Not Application.Intersect(Target, Range("C40")) Is Nothing Then
' Cancel = True
' SelectPayFreq.Show
' End If
' End Sub
End Sub