Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle True/False in a cell
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. Herold Winter wrote: 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 -- Herold Winter -- Dave Peterson |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle True/False in a cell
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 -- Herold Winter "Dave Peterson" schreef in bericht ... 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. Herold Winter wrote: 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 -- Herold Winter -- Dave Peterson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle True/False in a cell
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 -- Dana DeLouis Using Windows XP & Office XP = = = = = = = = = = = = = = = = = "Dave Peterson" wrote in message ... 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. Herold Winter wrote: 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 -- Herold Winter -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Is Cell D3 within 10% of B3 True or false? | Excel Discussion (Misc queries) | |||
Is Cell D3 within 10% of B3 True or false? | Excel Discussion (Misc queries) | |||
What's the best way to toggle between true and false in Excel? Hiall, My excel work involves a lot of toggling between true and false (booleantypes) ... and it's very repetitive... Is there a way to select a bunch ofcells, and press a key short-cu | Excel Discussion (Misc queries) | |||
Function to return True/False if all are validated as True by ISNU | Excel Worksheet Functions | |||
Use IF to change value in a different cell when TRUE (or FALSE)? | Excel Discussion (Misc queries) |