Doubleclick Yes, No and Blank - VBA

Garri

New Member
Joined
May 28, 2019
Messages
3
Hello everyone,

I found a Code for VBA to use double click in certain cell to activate Yes and No. However, I cannot to add to that code that it also show blank (or returns to the default result aka do not show anything).

Can anyone help me please?

P.s I am newbie.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address <> "C1" Then Exit Sub
Cancel = True
With Target
If .Value = "Yes" Then
.Value = "No"
Else
.Value = "Yes"
End If
End With
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
How about
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Target.Address(0, 0) <> "C1" Then Exit Sub
      Cancel = True
      With Target
      If .Value = "Yes" Then
         .Value = "No"
      ElseIf .Value = "No" Then
         .Value = ""
      Else
         .Value = "Yes"
      End If
   End With
End Sub
 
Upvote 0
Try:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    If Target.Address <> "$C$1" Then Exit Sub
    Cancel = True
    
    Select Case Target.Value
        Case "Yes": Target.Value = "No"
        Case "No": Target.Value = ""
        Case Else: Target.Value = "Yes"
    End Select
    
End Sub
 
Last edited:
Upvote 0
I'm late to the thread (as usual), but here is one more way to do this...
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Target.Address(0, 0) = "C1" Then
     Cancel = True
     Target.Value = Choose(1 + InStr(" YN", Left(Target.Value, 1)), "", "Yes", "No")
   End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top