Combo Box Question

bradley7

Board Regular
Joined
Feb 22, 2005
Messages
102
Hi

I have a array with 2 items in it, Name ane Price
how can i select a Name which i have feed into the combo box, using the position of the name in the list to get at to correct price?

example

select the 8th name in the combo box
then moving the right price (the 8th in this case) to a text box

brad
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
If you have Names in A1:A10 and their matching Prices in B1:B10, you could put code like this in the userform's code module.

Code:
Private Sub UserForm_Initialize()
    Dim oneCell As Range
    
    With ComboBox1
        .ColumnCount = 2
        .ColumnWidths = ";0"
        .BoundColumn = 2
        .TextColumn = 1
        For Each oneCell In Range("A1:A10")
            .AddItem oneCell.Value
            .List(.ListCount - 1, 1) = oneCell.Offset(0, 1)
        Next oneCell
    End With
End Sub

Private Sub ComboBox1_Change()
    TextBox1.Value = ComboBox1.Value
End Sub
 
Upvote 0
Code:
Dim NamePrice As Variant

Private Sub UserForm_Initialize()
    NamePrice = Array(Array("Apples", "Oranges", "Pears", "Bananas"), _
                      Array("$1", "$2", "$3", "$4"))
                      
    ComboBox1.List = NamePrice(0)
    
End Sub

Private Sub ComboBox1_Change()
    If ComboBox1.ListIndex <> -1 Then
        TextBox1.Value = NamePrice(1)(ComboBox1.ListIndex)
    Else
        TextBox1.Value = vbNullString
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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