CheckBox

CheckBox is one of the UserForm control. You can select and drag CheckBox on the UserForm. CheckBox Control is used to specify or indicate binary choice. That is either Turn on or off a value. When we use more checkboxs, you can select more than one CheckBox at a time on the UserForm. You can select multiple check boxes in a group box. Please find more details about CheckBox Control in the following chapter.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


VBA ActiveX CheckBox Control on the UserForm

  1. Go To Developer Tab and then click Visual Basic from the Code or Press Alt+F11.
  2. Go To Insert Menu, Click UsereForm. Please find the screenshot for the same.
  3. Drag a check box on the Userform from the Toolbox. Please find the screenshot for the same.
  4. Now, you can see the following code.
  5. Private Sub CheckBox1_Click()
    End Sub
    

    Note: In the above code ‘CheckBox1’ is the Check box name.

  6. Please add the following statements to the procedure.
  7. Private Sub CheckBox1_Click()
    If UserForm2.CheckBox1.Value = True Then
    MsgBox "Checkbox has Checked",, "Checkbox"
    Else
    MsgBox "Checkbox has UnChecked",, "Checkbox"
    End If
    End Sub
    
  8. Run the above macro by pressing F5.
  9. Check and uncheck the check box twice to get the two different outputs.

Add dynamic CheckBox Control on the UserForm using VBA

Please find the following steps and example code, it will show you how to add dynamic checkbox control on the userform.

  1. Add command button on the userform from the toolbox.
  2. Right click on the command button, click properties
  3. Change the command button caption to ‘Create_Checkbox’
  4. Double click on the command button
  5. Now, it shows following code.
  6. Private Sub CommandButton1_Click()
    End Sub
    
  7. Call the below procedure named ‘Add_Dynamic_Checkbox’ and find the below procedure to run.
  8. Private Sub CommandButton1_Click()
    Call Add_Dynamic_Checkbox
    End Sub
    

    Procedure to call in the Command Button:

    Sub Add_Dynamic_Checkbox()
    'Add Dynamic Checkbox and assign it to object 'Cbx'
    Set Cbx = UserForm2.Controls.Add("Forms.CheckBox.1")
    'Assign Checkbox Name
    Cbx.Caption = "Checkbox2"
    'Checkbox Position
    Cbx.Left = 10
    Cbx.Top = 10
    End Sub 
    
  9. Now, click F5 to run the macro, click ‘Create_Checkbox’ button to see the result.
  10. You can see the created dynamic check box in the following screen shot.
  11. output:

Select or UnSelect a CheckBox using VBA?

Please find the below code to know how to select or UnSelect a check box using VBA. In the below example we are using value property of the check box to select or UnSelect a check box.

‘ To select check box 
CheckBox1.Value=True
‘ To unselect check box 
CheckBox1.Value=False

Check if a check box is selected or not using VBA

Please find the below code to know how to check if a check box is selected or not using VBA. In the below example we are using value property of the check box.

Sub ChkBox_Ex1()
If CheckBox1.Value = True Then 
MsgBox “CheckBox has selected”
Else
MsgBox “CheckBox has not selected”
End If
End Sub

More details about Check box control

Here is the link more about how to add check box control on the Worksheet or UserForm in Excel.
Read More …

Here is the one more link to more about how to add check box control on the Worksheet or UserForm using VBA in Excel.
Read More …

Here is the one more link to more about how to remove check box control on the Worksheet or UserForm in Excel.
Read More …

LIMITED TIME OFFER

Related pages


how to protect file in excel with passwordvba excel last rowexcel 2007 autosave locationvisual basic check boxvba open text filevba variant arraydelete duplicate values excelvba excel codingexcel color indexexcel print macrovba update sqlmerge and center excel 2007how to disable a macro in excelms excel sortingexcel vba functionshortcut keys to excelremoving duplicates excelconcatenate on excelexcel what if statementsexcel adomerge tabs excelvba data entrycomparison operators excelhow to write heading in excelworksheet function in excelexcel macro to compare two columnsconsolidate in excelmicrosoft excel tables tutorialvba command button clickhow to merge worksheets in excelcount columns excelunprotect vbahow to lookup in excelexcel combining worksheetssoftware costing templatewritten test questions and answers for freshersvba hyperlink excelfor vba stepvlookup functionsexcel samples sheetsexcel 2007 remove duplicatescombobox codemerging excel columnscreate new worksheet vbamsgbox vba yes noadvanced excel 2007 formulas with examplestrim vbasimple explanation of vlookuphow to unshare a workbookchange row height in excel 2010vba sort ascendingddl and dml statements in sqlhow to format rows in excelfilter pivot table based on cell valuehow to highlight a column in excelvba application calculationvba excel offsetcopy to clipboard vbavba code to close a formapply chart template excelunhide worksheet excel 2010worksheetfunction.vlookupvba check file existssample vba programssql groupingnested if function excel 2010 exampleexcel vba with functionunmerge cells excel 2010access vba opendatabasemerge center excelbreak excel workbook passwordvba variablesexcel vba rows selectvba emptymultiple columns in excel