I created a userform that is populated with checkboxes based off of the cell values on multiple worksheets. I named the checkboxes based off of the cell values (none of them are the same) but the number of cells will change over time so I wanted to have a code populate the userform rather than manually put each checkbox in. I want to be able to call on specific cell value information if its checkbox is clicked but my code isn't working. I think I need to create a dynamic checkbox variable that changes each time. I'm currently unable to call on any of the checkboxes except the very last one.
Public chkBox As MSForms.CheckBox
Public Sub UserForm_Initialize()
MemNumCombo.Clear
Dim o As Long
Dim chkL As Double
Dim chkT As Double
Dim chkH As Double
Dim chkW As Double
chkL = 125
chkT = 5
chkH = 15
chkW = 80
o = 2
Do Until Worksheets("Operations").Cells(o, 1).Value = "Division:"
Set chkBox = Me.Controls.Add("Forms.CheckBox.1", Worksheets("Operations").Cells(o, 1).Value & Worksheets("Operations").Cells(o, 3).Value & "Check")
chkBox.Caption = Worksheets("Operations").Cells(o, 1).Value & " " & Worksheets("Operations").Cells(o, 3).Value
chkBox.Left = chkL
chkBox.Top = chkT + (o - 1) * 20
chkBox.Height = chkH
chkBox.Width = chkW
o = o + 1
Loop
'...
End Sub
I know when the code runs the chkBox's name is correct but I can't call on the chkBox by it's name later on. When the code is done running, I can only call on the last chkBox.