PDA

View Full Version : Solved: 3 mulitilink comboboxes



lehgzil
09-20-2010, 02:12 AM
hi im new here, and new to vba for excel also,
im making a project on which i have multiple comboboxes which are link to the previous combobox(eg combobox1 link to combobox2 which is link to combobox 3 and so on.) and that the value of the later comboboxes are dependent on the previous.

on this example i shortened the list of comboboxes to two.

i have a button called Produce, bringin userform1 with 2 comboboxes and 2 command button.
i need a code that generates value of combobox 2 if i selected a value to combobox1.

an example is attached...

btw i tried if and else and case select, it didnt work or theres something wrong with my code.

i appreciate your help. thanks in advance.

Bob Phillips
09-20-2010, 03:35 AM
Option Explicit

Private Sub cmdCancel_Click()
'Unload the userform
Unload Me
End Sub

Private Sub cmdOkay_Click()
'Verify that an item was selected
Dim strname As String
If Me.ComboBox1.BoundValue & Me.ComboBox2.BoundValue _
= vbNullString Then
MsgBox "You did not choose an item!", vbOKOnly

Exit Sub
Else
MsgBox "You choose " & Me.ComboBox1.Text & ComboBox2.Text
Sheets("sheet1").Range("j1").Value = ComboBox1.Text
Sheets("sheet1").Range("k1").Value = ComboBox2.Text
End If
Unload Me
End Sub

Private Sub ComboBox1_Change()

With Me.ComboBox2

.Clear

Select Case ComboBox1.Value

Case "TUG"
.AddItem ("a")
.AddItem ("b")
.AddItem ("c")

Case "MLA"
.AddItem ("1")
.AddItem ("2")
.AddItem ("3")
End Select
End With
End Sub

Private Sub UserForm_Initialize()
'Load the combobox with a variety of household pets
With Me.ComboBox1
.AddItem ("TUG")
.AddItem ("MLA")
End With
End Sub

lehgzil
09-20-2010, 05:12 PM
yay thanks XLD... your code does it well... now i can follow this fir my multiple comboboxes, thanks thanks...
btw, sorry for the late reply...