Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel VBA 2007 - Combo Box
I am new to VBA.
I have two variables X with values x1, x2, x3 and Y with values y1, y2, y3, y4 I want to create two combo boxes for each of the variables. However, the values selected for variable Y is dependent on the values selected for variable X. For eg: If I select x1 for X, then the only possible outcomes for Y can by y3, y4; or is I select x2 then the only possible outcomes can be y1, y2, y3 and if I select x3 then the any value in Y can be selected. I want to write the code in VBA. Is this possible. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel VBA 2007 - Combo Box
Here is some sample code:
Private Sub UserForm_Initialize() Me.ComboBox1.AddItem ("X1") Me.ComboBox1.AddItem ("X2") End Sub Private Sub ComboBox2_Enter() If UCase(Me.ComboBox1) = "X1" Then Me.ComboBox2.Clear Me.ComboBox2.AddItem ("Y1") Me.ComboBox2.AddItem ("Y2") ElseIf UCase(Me.ComboBox1) = "X2" Then Me.ComboBox2.Clear Me.ComboBox2.AddItem ("Y2") Me.ComboBox2.AddItem ("Y3") Me.ComboBox2.AddItem ("Y5") End If End Sub -- Cheers, Shane Devenshire "aqualibra" wrote: I am new to VBA. I have two variables X with values x1, x2, x3 and Y with values y1, y2, y3, y4 I want to create two combo boxes for each of the variables. However, the values selected for variable Y is dependent on the values selected for variable X. For eg: If I select x1 for X, then the only possible outcomes for Y can by y3, y4; or is I select x2 then the only possible outcomes can be y1, y2, y3 and if I select x3 then the any value in Y can be selected. I want to write the code in VBA. Is this possible. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel VBA 2007 - Combo Box
Thanks. This is helpful, but how do I code it if the data is in excel already.
X - x1, x2, x3 range B3:B5 Y - y1, y2 , y3 range D3:D6 Thanks in advance "ShaneDevenshire" wrote: Here is some sample code: Private Sub UserForm_Initialize() Me.ComboBox1.AddItem ("X1") Me.ComboBox1.AddItem ("X2") End Sub Private Sub ComboBox2_Enter() If UCase(Me.ComboBox1) = "X1" Then Me.ComboBox2.Clear Me.ComboBox2.AddItem ("Y1") Me.ComboBox2.AddItem ("Y2") ElseIf UCase(Me.ComboBox1) = "X2" Then Me.ComboBox2.Clear Me.ComboBox2.AddItem ("Y2") Me.ComboBox2.AddItem ("Y3") Me.ComboBox2.AddItem ("Y5") End If End Sub -- Cheers, Shane Devenshire "aqualibra" wrote: I am new to VBA. I have two variables X with values x1, x2, x3 and Y with values y1, y2, y3, y4 I want to create two combo boxes for each of the variables. However, the values selected for variable Y is dependent on the values selected for variable X. For eg: If I select x1 for X, then the only possible outcomes for Y can by y3, y4; or is I select x2 then the only possible outcomes can be y1, y2, y3 and if I select x3 then the any value in Y can be selected. I want to write the code in VBA. Is this possible. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Combo box output excel 2007 | Excel Discussion (Misc queries) | |||
Combo box value does not update in Excel 2007 | Excel Discussion (Misc queries) | |||
Excel 2007 Combo Box questions | Excel Discussion (Misc queries) | |||
Combo box to link to SQL Database table in Excel 2007 | Excel Discussion (Misc queries) | |||
Excel VBA Combo Box Populating dependent on other combo box choices | Excel Programming |