Combobox Userform help needed

nzepeda

Board Regular
Joined
Nov 11, 2010
Messages
58
I was able to create a generic looking Userform with a Multipage in the middle, which has 3 pages.

I wrote this into the Initialize.

Code:
Private Sub UserForm_Initialize()
Dim Numb As Worksheet
Set Numb = Worksheets("Numbers")
Dim tCB As MSForms.ComboBox
Dim tLB As MSForms.Label
Dim Track As String
Dim Code As String
Dim oRow As Integer
Dim oCol As Integer
Dim cRow As Integer
Dim Tval As Integer
     
Tval = 10
oRow = 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 = "tName"
                .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 = "tCode"
                .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
    Next oCol
Tval = 10
oRow = 21
    For oCol = 15 To 69
        Track = Numb.Cells(oRow, oCol).Value
        If Track <> "" Then
            Set tLB = UserForm1.HostMP.Pages(0).Controls.Add("Forms.Label.1")
            With tLB
                .Name = "tName"
                .Caption = Track
                .Left = 25
                .Top = Tval
                .Height = 12
                .Width = 150
                .Font.Size = 8
            End With
            Set tCB = UserForm1.HostMP.Pages(0).Controls.Add("Forms.ComboBox.1")
            With tCB
                .Name = "tCode"
                .Left = 170
                .Top = Tval
                .Height = 16
                .Width = 150
                .Font.Size = 8
            For cRow = 22 To 41
                If Numb.Cells(cRow, oCol) Like "" Then
                    GoTo sP
                Else
                .AddItem Numb.Cells(cRow, oCol).Offset(0, 1).Value
                End If
            Next cRow
            End With
sP:
        Tval = Tval + 18
        End If
    Next oCol
    
    Tval = 10
    oRow = 41
    For oCol = 15 To 69
        Track = Numb.Cells(oRow, oCol).Value
        If Track <> "" Then
            Set tLB = UserForm1.HostMP.Pages(2).Controls.Add("Forms.Label.1")
            With tLB
                .Name = "tName"
                .Caption = Track
                .Left = 25
                .Top = Tval
                .Height = 12
                .Width = 150
                .Font.Size = 8
            End With
            Set tCB = UserForm1.HostMP.Pages(2).Controls.Add("Forms.ComboBox.1")
            With tCB
                .Name = "tCode"
                .Left = 170
                .Top = Tval
                .Height = 16
                .Width = 150
                .Font.Size = 8
            For cRow = 42 To 61
                If Numb.Cells(cRow, oCol) Like "" Then
                    GoTo cP
                Else
                .AddItem Numb.Cells(cRow, oCol).Offset(0, 1).Value
                End If
            Next cRow
            End With
cP:
        Tval = Tval + 18
        End If
    Next oCol
End Sub

What this does is looks at my Sheet "Numbers" in specific areas, O1:BV19 for page 2 of the multipage, O21:BV40 for page 1 of the multipage and O41:BV60 for page 3 of the multipage.

From what is in these ranges it will create a Label and a Combobox.

The Label will have the value of cells O1, the next label for that page will have the value in P1 and so on until a blank cell is found. This will be the same for the other pages. For every Label added and Combobox is added. The Combobox is populated with any values that are within the same Column as the value for the Label within rows 2:19, 22:39 and 42:59.

Up to this point everything is how I want it. What I am trying to figure out is how to then have my "OK" button to take the values selected from the Comboboxes and input into cells on a Sheet.

Only thing I can come up with so far is that I will somehow have to make it so that each Combobox has its own name, and have a loop or something to go through them and place the value where needed. This is purely speculation though.

Any help would be appreciated.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,224,585
Messages
6,179,702
Members
452,938
Latest member
babeneker

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