Create Cascading ComboBoxes in a UserForm
The following code creates cascading comboboxes, where ComboBox2 is dependent on the value selected from ComboBox1. It is assumed that you've already created a UserForm that contains two ComboBoxes.
Private Sub
ComboBox1_Change()
Me.ComboBox2.Clear
Select Case
Me.ComboBox1.Value
Case "A"
With Me.ComboBox2
.AddItem
"Adam"
.AddItem
"Allen"
.AddItem
"Andy"
End With
Case "B"
With Me.ComboBox2
.AddItem
"Barb"
.AddItem
"Bill"
.AddItem
"Bob"
End With
Case "C"
With Me.ComboBox2
.AddItem
"Carl"
.AddItem
"Charles"
.AddItem
"Chris"
.AddItem
"Cindy"
End With
End Select
End Sub
Private Sub
UserForm_Initialize()
With Me.ComboBox1
.AddItem
"A"
.AddItem
"B"
.AddItem
"C"
End With
End Sub
Where to Put the Code
- Open the workbook in which to store the code.
- Open the Visual Basic Editor (Alt+F11).
- In the Project Explorer window (Ctrl+R), right-click the UserForm, and select View Code.
- Copy and paste the above code into the code module for the UserForm.
- Return to Microsoft Excel (Alt+Q).
- Save the workbook.
Sample Workbook: Download