![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 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! |
|
|
|
|
|
#2 |
|
Banned
Join Date: Feb 2002
Posts: 1,582
|
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. |
|
|
|
|
|
#3 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
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 |
|
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
Thanks very much, they both work great!
|
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: Ahmedabad Gujarat
Posts: 303
|
I think same goal can be achieved by setting
Boundcolumn, ColumnCount and Column Width Property see my example file comboboxproperty from my download section http://www.pexcel.com/download.htm file nos is 23 nishith desai |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|