PDA

View Full Version : BeforeDoubleClick trouble



IRish3538
11-05-2016, 09:07 AM
So I'm making these ad-hoc checkboxes (because activex sucks) but can't seem to get this to fire correctly. If D1 is selected, unselect D2 (that works). but if D2 is selected, uncheck D1 doesn't work. I know it's because when D2 is selected, it makes the target D1 and goes thru the progression again. Just can't figure out how to fix it. Any help would be greatly appreciated! Thanks!

The checkboxes are wingdings. chr(168) = unchecked, chr(254) = checked



Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'This is the first part that just checks/unchecks the boxes if they're pressed
If Not Intersect(Range("d1:d2"), Target) Is Nothing Then
Application.EnableEvents = False
Cancel = True
If Target.Value = Chr(254) Then
Target.Value = Chr(168)
Else
Target.Value = Chr(254)
End If
Application.EnableEvents = True
End If
On Error Resume Next

'This is my attempt at trying to uncheck the other thing
Select Case Target
Case Is = Range("d1")
If Target.Value = Chr(254) Then Range("d2:d5").Value = Chr(168)
Case Is = Range("d2")
If Target.Value = Chr(254) Then Range("d1").Value = Chr(168)
End Select
End Sub

SamT
11-05-2016, 10:40 AM
If Intersect(D1:D2, etc) is Nothing then exit Sub

Cancel = True
If Target.Row = 1 then etc
ElseIf Target.Row = 2 Then etc

mikerickson
11-05-2016, 03:10 PM
Its sounds like you are trying to emulate two option buttons. I may have gotten the


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim OtherCell as Range
'This is the first part that just checks/unchecks the boxes if they're pressed
If Not Intersect(Range("d1:d2"), Target) Is Nothing Then

Set OtherCell = Range("D3").Offset(0, - Target.Column)

Application.EnableEvents = False
Cancel = True
If Target.Value = Chr(254) Then
Target.Value = Chr(168)
'OtherCell.Value = Chr(168)
Else
Target.Value = Chr(254)
OtherCell.Value = Chr(168)
End If


Application.EnableEvents = True
End If
On Error Resume Next

End Sub