In a excel checkbox, it run when I put or remove the check mark in the checkbox. What is the function to make it run only when i put the check mark to the checkbox but not when i remove the check mark.
thanks
- Menu: View, Toolbars, put a checkmark before Visual Basic
- In the VB Toolbar, press the Control Toolbox window.
- In the Control Toolbox, select the checkbox and click on the worksheet to get CheckBox1
- Click the Properties button in the Control Toolbox
- Change any of the properties to what you want them to be
- Right-click on the check-box on the worksheet and choose View Code
- Finish the Event code:
- Private Sub CheckBox1_Click()
-
If CheckBox1 Then MsgBox "DoIt"
-
End Sub
Now, go back to Excel and exit the design mode with the Control Toolbox. Test and see. You should get a message only when checking.
Note -- in a regular macro module, you will need to qualify CheckBox1 with the sheet name:
- Sub Macro1()
-
'
-
' Macro1 Macro
-
If Worksheets("Sheet1").CheckBox1 Then MsgBox "Checked"
-
End Sub
Final note -- in the properties, before you write the code, you should change the name from CheckBox1 to something meaningful, like ChkVisio. Then in the rest of my instructions, change CheckBox1 to ChkVisio.