Check Box

 

A check box is a field which can be checked to store information. To create a check box in Excel VBA, execute the following steps.

1. On the Developer tab, click Insert.

2. In the ActiveX Controls group, click Check Box.

Create a check box in Excel VBA

3. Drag a check box on your worksheet.

4. Right click the check box (make sure Design Mode is selected).

5. Click View Code.

View Code

Note: you can change the caption and name of a control by right clicking on the control (make sure Design Mode is selected) and then clicking on Properties. Change the caption of the check box to MyCheckBox. For now, we will leave CheckBox1 as the name of the check box.

6. Add the following code lines:

If CheckBox1.Value = True Then Range("D2").Value = 1
If CheckBox1.Value = False Then Range("D2").Value = 0

7. Click the check box on the sheet (make sure Design Mode is deselected).

Result:

Check Box True

Check Box False

Although in some situations it can be useful to directly place a check box on your worksheet, a check box is particularly useful when placed on a Userform.