VBA to Check If CheckBox Is Checked in Excel (3 Ways)

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.


Download Workbook

You can download the free practice Excel workbook from here.


3 Ways to Check If CheckBox Is Checked with VBA in Excel

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.

Create checkbox to check if checkbox is checked in excel vba

  • 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.

View code to check if checkbox is checked in excel vba

  • An auto-generated code will be opened in the code window.

auto generated code to to check if checkbox is checked in excel vba

  • 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

VBA code to check if checkbox is checked in excel

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.

Result of VBA code to check if checkbox is checked in excel

Read More: Excel VBA: Form Control Checkbox Value (3 Examples)


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

VBA code to check if checkbox is checked in excel with text

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 (with Easy Steps)


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

VBA code to check if checkbox is checked in excel in msgbox

  • 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?


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

Sanjida Ahmed

Sanjida Ahmed

Hello World! This is Sanjida, an Engineer who is passionate about researching real-world problems and inventing solutions that haven’t been discovered yet. Here, I try to deliver the results with explanations of Excel-related problems, where most of my interpretations will be provided to you in the form of Visual Basic for Applications (VBA) programming language. Being a programmer and a constant solution seeker, made me interested in assisting the world with top-notch innovations and evaluations of data analysis.

We will be happy to hear your thoughts

Leave a reply

ExcelDemy
Logo