VBA ActiveX CheckBox Control on the UserForm
- Go To Developer Tab and then click Visual Basic from the Code or Press Alt+F11.
- Go To Insert Menu, Click UsereForm. Please find the screenshot for the same.
- Drag a check box on the Userform from the Toolbox. Please find the screenshot for the same.
- Now, you can see the following code.
- Please add the following statements to the procedure.
- Run the above macro by pressing F5.
- Check and uncheck the check box twice to get the two different outputs.
Private Sub CheckBox1_Click() End Sub
Note : In the above code ‘ CheckBox1 ’ is the Check box name .
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
Add dynamic CheckBox Control on the UserForm using VBA
Please find the keep up steps and case code, it will show you how to add dynamic checkbox master on the userform.
- Add command button on the userform from the toolbox.
- Right click on the command button, click properties
- Change the command button caption to ‘Create_Checkbox’
- Double click on the command button
- Now, it shows following code.
- Call the below procedure named ‘Add_Dynamic_Checkbox’ and find the below procedure to run.
- Now, click F5 to run the macro, click ‘Create_Checkbox’ button to see the result.
- You can see the created dynamic check box in the following screen shot.
Private Sub CommandButton1_Click() End Sub
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
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 downstairs example we are using value property of the determine box to select or UnSelect a crack 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 case we are using respect 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 condition on the Worksheet or UserForm in Excel.
Read More …