vba dynamically created checkboxes onclick events

北战南征 提交于 2019-12-12 04:19:31

问题


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

来源:https://stackoverflow.com/questions/43615084/vba-dynamically-created-checkboxes-onclick-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!