mardi 25 avril 2017

vba dynamically created checkboxes onclick events

I have a list of checkboxes on a userform created from a list on an Excel sheet. I want to have an additional checkbox that when checked, is testing the caption value of all the checkboxes in the list. If there is a match to a target string, these checkboxes should check as well. I can create the list but referencing the checkboxes after creation and triggering events is the issue. So far this is all I have:

Private Sub UserForm_Initialize()

Dim curColumn   As Long
Dim LastRow     As Long
Dim i           As Long
Dim chkBox      As MSForms.CheckBox

curColumn = 1 'column index

LastRow = Worksheets("Parts").Cells(Rows.Count, curColumn).End(xlUp).Row

For i = 2 To LastRow
    Set chkBox = Me.Controls.Add("Forms.CheckBox.1", "CheckBox_" & i)
    chkBox.Caption = Worksheets("Parts").Cells(i, curColumn).Value
    chkBox.Left = 5
    chkBox.Top = 25 + ((i - 1) * 20)
    chkBox.Width = 200
Next i

End  Sub




Aucun commentaire:

Enregistrer un commentaire