Method 1 – Embed VBA Macro to Check If a CheckBox Is Checked with a Numeric Value in Excel
Add a checkbox to examine whether the checkbox is checked or not. To create a checkbox:
- Go to the tab Developer -> Insert.
- From Controls, select Check Box from the ActiveX Controls group.
- A plus sign (+) will turn up. Drag the sign to draw a check box on the worksheet.
- Make sure that the Design Mode is selected.
- Right click the Checkbox and select View Code from the option list.
- An auto-generated code will be opened in the code window.
- Copy the following code and paste it inside the code.
If CheckBox1.Value = True Then Range("D3").Value = 1
If CheckBox1.Value = False Then Range("D3").Value = 0
This code will store 1 if the checkbox is checked, or if the checkbox is not checked then it will store 0 in Cell D3.
- Press F5 on your keyboard, or select Run -> Run Sub/UserForm from the menu bar. Or click the Run icon in the sub-menu bar to run the macro.
If applied successfully, you will see 0 in Cell D3 if your checkbox is not checked.
If you click the Checkbox, you will see the number in Cell D3 is automatically updated into 1.
Method 2 – Implement VBA to Examine Whether a CheckBox Is Selected or Not with a Text Value
Steps:
- Copy the following macro and replace the auto-generated code in the Checkbox code window with it.
If Sheet3.CheckBox1.Value = True Then
Sheet3.Range("C3") = "Checked"
Else
Sheet3.Range("C3") = "Unchecked"
End If
This code will display “Checked” if the checkbox is selected, or if the checkbox is not selected then it will display “Unchecked” in Cell C3.
- Run the code. If you have an unselected Checkbox, Cell C3 will show “Unchecked.”
If you select the Checkbox, “Checked” will be visible in Cell C3.
Method 3 – Apply Macro to Check If a CheckBox Is Checked via MsgBox in Excel
Steps:
- Insert the following macro in the Checkbox code.
If CheckBox1.Value = True Then
MsgBox "CheckBox is Checked!"
Else
MsgBox "CheckBox is not Checked!"
End If
- Run this code.
If the Checkbox is unchecked, a “CheckBox is not Checked!” message will appear in the MsgBox.
If the Checkbox is checked or if you click the Checkbox, the “CheckBox is Checked!” message will appear in the MsgBox.
Download the Workbook
Related Articles
- If Checkbox Is Checked Then Apply Formula in Excel
- Excel VBA: Form Control Checkbox Value
- What Can You Do with Cell Value If Checkbox Is Checked in Excel?
- Excel Checkbox: If Checked then Change Cell Color
<< Go Back to Excel CheckBox | Form Control in Excel | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!