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

Get FREE Advanced Excel Exercises with Solutions!

A checkbox is a field that 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 have to add a checkbox to examine whether the checkbox is checked or not. To create a checkbox:

  • First, go to the 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


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


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.

If the Checkbox is checked or if you click the Checkbox then the “CheckBox is Checked!” message will appear in the MsgBox.


Download Workbook

You can download the free practice Excel workbook from here.


Conclusion

To conclude, this article showed you 3 different ways 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


<< Go Back to Excel CheckBox | Form Control in Excel | Learn Excel

What is ExcelDemy?

ExcelDemy - Learn Excel & Get Excel Solutions Center provides online Excel training , Excel consultancy services , free Excel tutorials, free support , and free Excel Templates for Excel professionals and businesses. Feel free to contact us with your Excel problems.
Sanjida Ahmed
Sanjida Ahmed

Sanjida Ahmed, who graduated from Daffodil International University with a degree in Software Engineering, has worked with SOFTEKO since 2021. She has written over 100 articles on Excel & VBA and, since 2022, has worked as the Project Manager of the Excel Extension Development Project in the Software Development Department. Since starting this software development, she has established an outstanding workflow encompassing a full SDLC. She always tries to create a bridge between her skills and interests in... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo