A checkbox is a field which performs according to the input. Implementing VBA is the most effective, quickest and safest method to run any operation in Excel. In this article, we will show you how to check if a checkbox is checked in Excel with the VBA macro.
VBA to Check If CheckBox Is Checked in Excel: 3 Ways
In this section, you will learn how to examine if a checkbox is checked in Excel with numeric value, text value and via msgbox in VBA.
1. Embed VBA Macro to Check If CheckBox Is Checked with Numeric Value in Excel
First, we need to create a checkbox to examine whether the checkbox is checked or not. To create a checkbox:
- First, go to tab Developer -> Insert.
- Second, from the appeared options of 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.
- Then, right click the checkbox and select View Code from the option list.
- An auto-generated code will be opened in the code window.
- Later, 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 piece of code will store the number 1 if the checkbox is checked, or if the checkbox is not checked then it will store 0 in Cell D3.
- Now, press F5 on your keyboard or from the menu bar select Run -> Run Sub/UserForm. You can also just click on the small Run icon in the sub-menu bar to run the macro.
After the successful code execution, you will see 0 in Cell D3 if your checkbox is not checked.
And if you click the checkbox now, then you will see the number in Cell D3 is automatically updated into 1.
Read More: Excel VBA: Form Control Checkbox Value
2. Implement VBA to Examine Whether CheckBox Is Selected or Not with Text Value
In the previous section, we learned how to display numeric values according to the type of the checkbox. In this section, we will see how to execute the same task but this time it will display text value in Cell C3 based on whether the checkbox is selected or not.
Steps:
- In the code window, copy the following macro and paste it inside the auto-generated code.
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.
- Next, Run the code and if you have an unselected checkbox then in Cell C3 there will be “Unchecked” presented.
Then, if you select the checkbox then “Checked” will be visible in Cell C3.
Read More: How to Filter Checkboxes in Excel
Similar Readings
- How to Add Checkbox in Excel without Using Developer Tab
- How to Align Checkboxes in Excel
- How to Resize Checkbox in Excel
3. Apply Macro to Check If CheckBox Is Checked via MsgBox in Excel
Here, we will see how to determine whether the checkbox is checked or not via Excel MsgBox.
Steps:
- In the code window, copy the following macro and paste it inside the auto-generated code.
If CheckBox1.Value = True Then
MsgBox "CheckBox is Checked!"
Else
MsgBox "CheckBox is not Checked!"
End If
- Later, Run this code.
If the checkbox is unchecked then “CheckBox is not Checked!” message will appear in the MsgBox.
And if the checkbox is checked or if click the checkbox then “CheckBox is Checked!” message will appear in the MsgBox.
Read More: What Can You Do with Cell Value If Checkbox Is Checked in Excel?
Download Workbook
You can download the free practice Excel workbook from here.
Conclusion
To conclude, this article showed you 3 different ways on how to check if a checkbox is checked in Excel with the VBA macro. I hope this article has been very beneficial to you. Feel free to ask any questions regarding the topic.
Related Articles
- How to Count Checkboxes in Excel
- How to Group Checkboxes in Excel
- How to Link Multiple Checkboxes in Excel
- Excel Checkbox: If Checked then Change Cell Color
- If Checkbox Is Checked Then Apply Formula in Excel
- How to Apply Conditional Formatting Using Checkbox in Excel
- How to Remove Checkboxes from Excel