I have written a UserForm that when initialized will add comboboxes and fill in the values if data is the proper place.
My issue is that the code I have written that creates the CBs is a loop, so I am having trouble naming each CB so I can pass the Value selected by the user when they select OK.
As of now it will pass the value of the last CB made and only that value.
Is there a way to name each CB with a number so that I can have some sort of loop later that checks the # and they puts that in its proper place?
Here is the loop I am currently using
The first part of this adds a label to the left of the CB which pretty much tells the user what they are selecting.
For the name of the CB I wanted to put something like this
Where cbo would start as # 1 and increase as another CB was added. I could not get this to work properly though, any thoughts on how I could fix this would be much appreciated.
My issue is that the code I have written that creates the CBs is a loop, so I am having trouble naming each CB so I can pass the Value selected by the user when they select OK.
As of now it will pass the value of the last CB made and only that value.
Is there a way to name each CB with a number so that I can have some sort of loop later that checks the # and they puts that in its proper place?
Here is the loop I am currently using
Code:
Tval = 10
oRow = 1
cbo = 1
For oCol = 15 To 69
Track = Numb.Cells(oRow, oCol).Value
If Track <> "" Then
Set tLB = UserForm1.HostMP.Pages(1).Controls.Add("Forms.Label.1")
With tLB
.Name = "ltName"
.Caption = Track
.Left = 25
.Top = Tval
.Height = 12
.Width = 150
.Font.Size = 8
End With
Set tCB = UserForm1.HostMP.Pages(1).Controls.Add("Forms.ComboBox.1")
With tCB
'' .Name = "ltCode"
.Left = 170
.Top = Tval
.Height = 16
.Width = 150
.Font.Size = 8
For cRow = 2 To 19
If Numb.Cells(cRow, oCol) Like "" Then
GoTo lP
Else
.AddItem Numb.Cells(cRow, oCol).Offset(0, 1).Value
End If
Next cRow
End With
lP:
Tval = Tval + 18
End If
cbo = cbo + 1
Next oCol
The first part of this adds a label to the left of the CB which pretty much tells the user what they are selecting.
For the name of the CB I wanted to put something like this
Code:
.Name = "ltCode"& cbo &""
Where cbo would start as # 1 and increase as another CB was added. I could not get this to work properly though, any thoughts on how I could fix this would be much appreciated.