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

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.

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

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

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


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

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.

  • 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

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

  • 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


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

Get FREE Advanced Excel Exercises with Solutions!
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