Run Code from User Form when Check box Clicked

rpaulson

Well-known Member
Joined
Oct 4, 2007
Messages
1,368
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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
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,213,531
Messages
6,114,172
Members
448,554
Latest member
Gleisner2

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