Toggle True/False in a cell

  • Thread starter Thread starter Herold Winter
  • Start date Start date
H

Herold Winter

Hello,

I would like to know if the following is possible:

If you click on a cell the value will toggle between true or false.
I want to add a column which has that kind of cells.
I want to use it for marking purposes.

Sorry, for my bad englisch
 
How about this:

Option Explicit

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)

If Target.Cells.Count > 1 Then Exit Sub
If Target.Column <> 7 Then Exit Sub

On Error GoTo errHandler:
Application.EnableEvents = False
Cancel = True
If TypeName(Target.Value) = "Boolean" Then
Target.Value = Not Target.Value
ElseIf IsEmpty(Target.Value) Then
Target.Value = True
End If

errHandler:
Application.EnableEvents = True

End Sub

Rightclick on the the worksheet tab that should have this behavior. Select View
Code and paste this in.

The macro looks for a rightclick when you're in column 7 (G). Modify that if
required.
 
Hello Dave,

I have test your code and it works perfectly.
It is excactly what i needed.

Thank you very much for your quick reaction
 
Dave's method is better, but just another idea...

With Range("A1")
If WorksheetFunction.IsLogical(.Item(1)) Then
.Value = Not .Value
End If
End With
 
Back
Top