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


excel macro passwordexcel macros usescombine multiple excel worksheets into oneexcel 2013 pivot table tutorialexcel delete duplicate rowsexcel listbox vbahow to record macrosvlookup tutorial for beginnerspassword unprotect excelinsert rows excel shortcutgridlines in excel definitionhow to check duplicates in excel 2007unlock excel workbook without passwordexcel vba named rangeuser input in vbavba data validation listvba debuggerunlock workbook excelvlookup meaninghow to combine multiple excel sheets into one sheethow to unprotect a workbook in excel 2010dml ddlabout genpact interview questions and answerspassword protecting excel 2007vba string containsdcl languageworksheet tab excelhow to concatenate in vbamultiple if condition in excelinsert checkboxes in excelvba changevba cell valueexcel hyperlink functionopening xlsm filesexcel vba class module exampleoutlook meeting minutes templatevba popup boxddl sql statementsvba autofilter rangehow to use lookup function in excel 2010count rows excelwriting vba macrosexcel vba recordset getrowswhat is the iferror function in excelcell vba exceltick on excelinsert row vba excelappend tables in excelopen file in excel vbaword vba userformrows.count vbasql query to excelhow to remove blank columns in excelcopy to clipboard vbaexcel vba copy destinationms excel rowscreate duplicate rows in excelexcel formula tutorialsql tutorial advanced with examplesweekly calendar template 2014 excelgantt chart excel 2003 templateexcel vba borderaroundexcel vba userform tutorialddl comandshow to unlock macro password in excelexcel macro templateexcel event calendar templatepivot table excel vbasoftware development estimation spreadsheetfinding doubles in excelfilefilter vbaremove header in excel