Macro Click to change from false to true

ed.ayers315

Board Regular
Joined
Dec 14, 2009
Messages
166
Hi Folks,

Can not find a post for this; I need a macro to to change a cell value from false to true or from 0 to 1.

I have a number of cells I want to be able to just click or double click the cells and change it back and forth as needed.

I tried the check boxes for this but they do not fill my needs.

I have different sheets with multiple cells I need to do this in.

H61 & I61

H63 & I61

H65 & I61

And so on

Thanks for any help
 
Hello

For example, an event for the worksheet where you want this to work on cells H61 and I61:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    
    If Not Application.Intersect(Target, Range("H61:I61")) Is Nothing Then
        Target.Value = Not Target.Value
    End If

End Sub

Please extend for different ranges and / or different sheets (this could be a Workbook_SheetBeforeDoubleClick event in the ThisWorkbook section of the workbook's event code).
 
Upvote 0
Try like this starting with True or False in the cells. Right click the sheet tab, select View Code and paste in

Rich (BB code):
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("H61,H63,H65,I61")) Is Nothing Then Exit Sub
Cancel = True
Target.Value = Not Target.Value
End Sub

Modify the range in red to suit. Double click a cell to swap its value.
 
Upvote 0
Hi wigi,

Thanks for the reply. I tried this but it changes the value from 0 to -1 then -1 to 0.

Is there a way to get it to do 1 to 0 then 0 to 1?
 
Upvote 0
try a doubleclick event in the sheet's code module:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("H61:I61,H63:I63,H65:I65,H67:I67,H69:I69,H71:I71")) Is Nothing Then
  Cancel = True
  If VarType(Target.Value) = vbBoolean Then
    Target.Value = Not (Target.Value)
  Else
    Target.Value = IIf(Target.Value = 1, 0, 1)
  End If
End If
End Sub
How far does 'and so on' go?
 
Upvote 0
Thanks Folks,

I had to change the 1, 0, 1 to 1, NULL, 1

It is working the way I need it to, you're great!

Thanks
 
Last edited:
Upvote 0

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