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.



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"
    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 
‘ To unselect check box 

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”
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 …


Related pages

how to use iferror function with vlookup in excel 2010creating drop down menus in excel 2007fso objectunshare workbookmerge and center in excel 2010isevendcl definitionautofilter macrohow to combine duplicate rows in excelexcel loopsfile exists vbacalendar template excel 2014remove blank columns in excelado excel vbaunprotect workbook in excel 2010writing macros in excel tutorialexcel sum if formulasql query for sorting data in ascending orderexcel macro worksheetexcel project plan templateif statement excel vbaadodb connection string sql serverlearning vba codevba insurancevariable types vbahow to insert comment in excelvba excel pastespecialvba and macros for microsoft excelvba worksheet rangeexcel automatic color codingvba dirmicrosoft excel estimate templateproject management templates for excelexcel cost estimate templatemacro functions in excelshortcut for hide in excelhow to remove blank rows excelvba gotostacked bar chart excel 2010excel vba stop macromacros excel 2003excel forgot password to unprotect sheetmacro enabled workbookmacros in vbaactiveworkbook.saveexcel add ins freewareexcel hide a worksheetfinancial dashboards in exceladvanced sql interview questions pdfremove blank cells in excel 2010vba for stepunhide personal workbookexcel unprotect sheet commandhow to append excel fileshow do you check for duplicates in exceliserror in excelunprotect excel onlinecreate activex controlexcel subtract two datesexcel vba open csv filedelete file excel vbaexcel vba connectiontrending analysis excelexcel vba errdelete activex controlexcel 2010 delete duplicateshow do i unhide columns in excelrefresh excel sheetsql coding interview questionsexcel 2010 vlookup exampleall formulas of excel 2007 with examplevba for access tutorialoffset example excelvlook up examplemultiple ifs in excelactivex excelhow to hide columns in excel 2007excel.workbooks.addexcel identify duplicates in columnexcel 2007 find duplicateshow to unprotect excel filecost estimation software free download