Need help in creating dynamic drop down list in userform

K

kiwis

Hi

I have a userform which allows user to enter data to a worksheet.

The user form have 6 items, 2 of which are dependent on each other.
i have created 6 combobox.
combobox 2 contains drop down list {mode of transport, wheels, no
wheels}
combobox 3 needs to depend on combobox2 selection,
eg combobox2 choose wheels, then combobox3 should show a list
{bus, car, bicycle}
if combobox2 choose no wheels, then combobox3 should show a
list {walk, swim, run}

i'm not sure how to make the combobox3 drop down list to show the
correct list depending on
the selection in combobox2.

partial code
Private Sub UserForm_Initialize()


'drop down list for group <-----combobox 2
For Each cGrp In ws.Range("Grp")
With Me.cboGrp
.AddItem cGrp.Value
.List(.ListCount - 1, 1) = cGrp.Offset(0, 1).Value
End With
Next cGrp

'drop down list depend on what user choose in combobox2 <-----
combobox3
Select Case cbGrp
Case wheels
'drop down list for wheels type
For Each cModel In ws.Range("wheellist")
With Me.cboModel
.AddItem cModel.Value
.List(.ListCount - 1, 1) = cModel.Offset(0,
1).Value
End With
Next cModel

Case nowheels
'drop down list for nowheels
For Each cModel In ws.Range("nowheellist")
With Me.cboModel
.AddItem cModel.Value
.List(.ListCount - 1, 1) = cModel.Offset(0,
1).Value
End With
Next cModel
End Select

The above code does not work, it will always show the wheellist when
either of the choice is selected.

Thank you for helping =)
 
I

Incidental

Hi

one way of doing it would be to use array's this is fine if your
options will not need to change on a regular basis

Private Sub ComboBox2_Change()

Select Case ComboBox2.Value

Case "Wheels"

ComboBox3.List = Array("bus", "car", "bicycle")

Case "No Wheels"

ComboBox3.List = Array("walk", "swim", "run")

End Select

End Sub

hope this helps

S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top