combo box question

robfo0

Active Member
Joined
Feb 19, 2002
Messages
281
Hi everyone,

Quick question. I have a userform that has a combo box on it. I populate the combo box by using the:

Private Sub Userform_Initialize()
With Me.combobox1
.additem "first"
.additem "second"]
end with
end sub

The question is regarding the value of the combo box selection. Is there a way to have the combo box display, as in my code example, "first", but then when i ask for me.combobox1.value have it return something else, such as "1" or something to that effect.

My goal is to have a simple statement in the combobox which users will see, but their selection will lead to a value which i need and predefined.

Please let me know if this isnt clear enough. thanks for any help!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi Robfo0

Sounds like an ideal situation for the choose Function.


Private Sub ComboBox2_Change()

If ComboBox2.ListIndex > -1 Then
MyRealVal = Choose(ComboBox2.ListIndex + 1, 1, 2, 3, 4)
End If

End Sub

The above code parses a pre-set value to the
Global variable "MyRealVal" so if the user selected the first item in the Combo list it would parse 1, if the chose the second item it would parse 2 etc.
 
Upvote 0
On 2002-03-18 22:33, robfo0 wrote:
Hi everyone,

Quick question. I have a userform that has a combo box on it. I populate the combo box by using the:

Private Sub Userform_Initialize()
With Me.combobox1
.additem "first"
.additem "second"]
end with
end sub

The question is regarding the value of the combo box selection. Is there a way to have the combo box display, as in my code example, "first", but then when i ask for me.combobox1.value have it return something else, such as "1" or something to that effect.

My goal is to have a simple statement in the combobox which users will see, but their selection will lead to a value which i need and predefined.

Please let me know if this isnt clear enough. thanks for any help!

Use a select case and just reference the
new value here eg.

Private Sub ComboBox1_Change()

Select Case ComboBox1.ListIndex

Case 0
MyNewValue = whatever
Case 1
MyNewvalue = whatever
End Select

End Sub


Ivan
 
Upvote 0

Forum statistics

Threads
1,213,554
Messages
6,114,280
Members
448,562
Latest member
Flashbond

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