I have a spreadsheet with a list of values in column A that I want to
show up as checkboxes on a userform. The current code crashes when it
tries to add a caption to the checkbox. I get a runtime error "Could
not find the specified object"
The actual code would call a function to determine how many rows in
column A which will vary, and I'll add code to size the form and
manipulate the checkboxes to fit.
Private Sub UserForm_Initialize()
Dim iRow As Integer
Dim iLeft As Integer
Dim ctlCheckBox As Control
Dim sName As String
Dim iNumRows As Integer
Dim iTop As Integer
Worksheets("Hour Per Equipment").Activate
iTop = 10
For iRow = 3 To iNumRows
If Cells(iRow, "A") <> "" Then
Set ctlCheckBox = frmEqpDetails.Controls.Add("frmEqpDetails.VisChkbox.1", "cb" & iRow)
sName = "cb" & iRow
'I tried using ctlCheckBox sub for sName-same result
frmEqpDetails.Controls(sName).Caption = Cells(iRow, "A")
Me.Controls(sName).Left = iLeft
ctlCheckBox.Top = iTop
iTop = iTop + 10
End If
Next iRow
End Sub
Bookmarks