Hello I'm trying to make a userform where it creates labels during runtime but the label values are based on a value that is selected from a combobox in the userform. The value is a named range, the code below can make a number of textboxes during runtime based on a value from a inputbox. I also need the quantity of the text boxes to be same of how many values there is in a named range. Is there anyone that canhelp? I attached the file as well. Test_File.xlsm
Code
Private Sub UserForm_Initialize()
Dim i As Long
number = InputBox("Enter no of text-boxes you wish to create at run-time", "Enter TextBox Number")
Dim txtBl As Control
For i = 1 To number
Set txtBl = Controls.Add("Forms.TextBox.1")
With txtBl
.Name = "txtBox" & i
.Height = 20
.Width = 150
.Left = 20
.Top = 20 * i * 1
End With
Next i
End Sub
Private Sub CommandButton1_Click()
Dim p As Long
For p = 1 To number
'Cells(l, p) = Controls("txtBox" & p).Text
Cells(p, 1) = Controls("txtBox" & p).Text
Next p
End Sub
Display More