An Excel VBA checkbox is a field which can be checked to store information. Learn how to draw a checkbox on your worksheet and how to refer to a checkbox in your code.
Excel 2010 and Excel 2007 users. Click on Insert from the Developer tab and then click on Check Box in the ActiveX Controls Section.
Excel 2003 users. Click on Check Box from the Control ToolBox.
1. Draw a checkbox on your worksheet.
You can change the caption of the checkbox by right clicking on the checkbox and then clicking on Properties and Caption (make sure Design Mode is selected).
You can change the name of the checkbox by right clicking on the checkbox and then clicking on Properties and Name. If you choose to do this, remember to refer to this name in your code. it is good practice to change the names of controls. This will make your code easier to read when you have more controls. For now, we will leave Checkbox1 as the name of the checkbox since we only have one checkbox in this example.
To refer to a checkbox in your Excel VBA code, execute the following steps:
1. Right click on the checkbox. Click on View Code. Add the following code lines:
If CheckBox1.Value = True Then Range("C2").Value = 1
If CheckBox1.Value = False Then Range("C2").Value = 0
2. Exit the Visual Basic Editor and check the checkbox.
Although in some situations it can be useful to directly place a checkbox on your worksheet, a checkbox is particularly useful when placed on a Userform.