Run Code from User Form when Check box Clicked

rpaulson

Well-known Member
Joined
Oct 4, 2007
Messages
1,428
I have the following code in my Private Sub UserForm_initialize() section of my user form.

It will programmatically create many check boxes. this part actually works as planned.

VBA Code:
r = 1
For c = 2 To 14
    Set chkBox = Me.Controls.Add("Forms.CheckBox.1", "CheckBox_" & c)
    chkBox.Caption = Cells(10, c).Value
    chkBox.Left = 500
    chkBox.Top = 50 + ((r - 1) * 20)
    
    If Columns(c).ColumnWidth = 0 Then chkBox.Value = True 'delaut check boxes to true if data in row 11
    r = r + 1
Next c

the issue is, I do not know how to trigger a click event

The below does not seem to work:
VBA Code:
Private Sub CheckBox_3_Click()
MsgBox "Box 3 clicked"
End Sub

any ideas?

Thanks,
Ross
 
Logit,

I want the code to run when the CHECK BOX is clicked, NOT CommandButton2_Click
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
VBA Code:
Private Sub CheckBox6_Click()
If Me.CheckBox6.Value = True Then
    Range("A7").Select
    ActiveCell.Value = "BOX 6"
    Range("A1").Select
    MsgBox "Done"
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top