Combobox - select first or second value from two column list

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hopefully an easy one:

I have a ComboBox on my userform that is populated with a two-column list (a numeric field and a string (textual) one). Based on a toggle button, I would like the combobox to return either the numeric field of the selected row or the string field of the selected row.

My problem is I do not know how to specify in code which field (numeric or string) the combobox should pull the value from to return.

Any assistance greatly appreciated!

Richard
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Richard

Perhaps something like this.
Code:
Private Sub ComboBox1_Change()
    Select Case True
        Case ToggleButton1
            MsgBox ComboBox1.Column(0)
        Case Else
            MsgBox ComboBox1.Column(1)
    End Select
End Sub
 
Upvote 0
Norie - thanks for the reply and I can see if I copy & paste your code into the userform code module that it returns the applicable field value just as I requested when I select a particular row from my combobox.

However, I do not seem to be able to set what value is then displayed in the combobox after selection (eg if I toggle for the textual field (which is the second column)) and then select a row from my combobox, your code makes a msgbox appear with the text "Gross Premiums" but the value displayed by the combobox is still its numeric equivalent "1001".

Have I managed to explain myself here, and can you suggest a solution?

Thanks

Richard
 
Upvote 0
Try:

Code:
Private Sub UserForm_Initialize()
    ToggleButton1.Value = False
End Sub

Private Sub ToggleButton1_Click()
    If ToggleButton1.Value = False Then
        ComboBox1.TextColumn = 1
    Else
        ComboBox1.TextColumn = 2
    End If
End Sub
 
Upvote 0
So you wanted to change what was displayed in the combobox?
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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