lundi 22 mai 2017

Dynamic Checkbox select all

I have created a userform with a dynamic checkbox using the below code. I am struggling to figure out how to add a select all/unselect all checkbox at the bottom (or anywhere) since the list is dynamic. Any assistance will be appreciated.

Private Sub UserForm_Initialize()

'Create Checkboxes form with director names

Dim lRow        As Long
Dim i           As Long
Dim chkBox      As MSForms.CheckBox

lRow = Cells(Rows.Count, 2).End(xlUp).Row

Sheets("Directors_Database").Activate

For i = 4 To lRow

    Set chkBox = Me.Controls.Add("Forms.CheckBox.1", "CheckBox_" & i)
    chkBox.Caption = Worksheets("Directors_Database").Cells(i, 2).Value
    chkBox.Left = 5
    chkBox.Top = 5 + ((i - 2) * 20)
    chkBox.Width = 350

Next i

Set chkBox = Nothing

End Sub




Aucun commentaire:

Enregistrer un commentaire