ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need help in creating dynamic drop down list in userform (https://www.excelbanter.com/excel-programming/398077-need-help-creating-dynamic-drop-down-list-userform.html)

kiwis

Need help in creating dynamic drop down list in userform
 
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 =)


Incidental

Need help in creating dynamic drop down list in userform
 
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



kiwis

Need help in creating dynamic drop down list in userform
 
Thanks Incidental for providing help, fixed it,
thanks ;

On Sep 25, 5:34 pm, Incidental wrote:
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





All times are GMT +1. The time now is 12:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com