I have only been writing vba code for 5 days, so I don't know what that is or how to do it.
But I reset my thinking and tried to set it up as checkboxes instead of a listbox with checks. I think this will work better for the latter functionality if I can get the textboxes to become visible. The problem I am seeing is that I cannot set up a Click procedure sub on the checkboxes that I am creating because those are being created in the userform_initialize sub
Private Sub UserForm_Initialize()
Dim cCntrl As Control
Dim cChk As Control
Dim cCap As Control
Dim i As Integer
Dim item As Integer
Text = Worksheets("background").Range("C2").Value
item = Worksheets("background").Range("D2").Value
For i = 1 To Text
Set cCntrl = Me.Controls.Add("Forms.TextBox.1", "TextBox" & i, False)
With cCntrl
.Width = 20
.Height = 12
.Top = i * 13.5 + 5
.Left = 200
.ZOrder (0)
.Font.Size = 6
End With
Set cChk = Me.Controls.Add("Forms.CheckBox.1", "CheckBox" & i, True)
With cChk
.Width = 50
.Height = 20
.Top = i * 13.5 + 5
.Left = 10
.ZOrder (0)
.Font.Size = 10
.Caption = Cells(i + 3, 6).Value
End With
Next i
End Sub
Private Sub Checkbox_Click()
Text = Worksheets("background").Range("C2").Value
Dim x As Integer
For x = 1 To Text
If Me.Controls("CheckBox" & x).Value = True Then
Me.Controls("TextBox" & x).Visible = True
Else
Me.Controls("TextBox" & x).Visible = False
End If
Next x
End Sub
Everything in the Checkbox_Click sub portion of the code above does not work because it is not tied to a specific checkbox...
Bookmarks