Userform creating Comboboxes on initialize naming issue

nzepeda

Board Regular
Joined
Nov 11, 2010
Messages
58
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

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.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,224,597
Messages
6,179,812
Members
452,945
Latest member
Bib195

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top