I'm creating an inventory management tool with Excel VBA. I've created code that gathers a list of names from a drop down box on Internet Explorer and puts them into an array.
What I need to do is something similar to vba create several textboxes comboboxes dynamically in userform, but I would be dynamically adding labels for the user names and textboxes for the number of FLNs each person would be receiving. These would then go into a predefined userform I've already created.
Per the code example above, I realize I can't use .Name = "Textbox" & i to rename the next label or textbox. i has to equal to an ever-changing list, so it can't be set in stone; hence why there has to be as many labels and textboxes as UBound(UserArray).
UPDATED
Private Sub CreateControl()
Dim newTxt As msforms.Control, newLbl
Dim i As Integer, TopAmt
Dim UserArray As String
TopAmt = 30
For i = LBound(MyArray) + 1 To UBound(MyArray) - 1
Set newLbl = MultipleOptionForm.Controls.Add("Forms.Label.1")
With newLbl
.Name = "Label" & i
.Left = 10
.Top = TopAmt
.WordWrap = False
.AutoSize = True
.Visible = True
.Caption = MyArray(i)
Debug.Print .Name,
End With
Set newTxt = MultipleOptionForm.Controls.Add(bstrProgID:="Forms.Textbox.1", Name:="Textbox" & i)
With newTxt
.Left = 150
.Top = TopAmt
.Visible = True
.Width = 20
Debug.Print .Name
End With
TopAmt = TopAmt + newTxt.Height
Next
MultipleOptionForm.Show
End Sub




iisCombobox1is a default name for the control, so I can't use"Combobox" & ito name it. They suggested that"ComboBox" & iwould work. That's not the bulk of my question. My question is how to dynamically add labels and textboxes to a predefined form. I thought putting the code for one each in afor...nextloop would work, but it leaves the form blank, for some reason.