I am trying to create dependant dropdown lists based on four different fields.
and am currently trying to make it so that I can have a list of options in one drop down list, and depending on what gets picked there, make it so that the
options for the second drop down list correspond with the first. I found vb code (by Matt) on one of the forums but couldn't make it work.
The screen shot of the excel file and the code are attached. I know it is full of mistakes. Hope someone can help me.
PHP Code:
Private Sub CommandButton1_Click()
Dim myLastRow As Integer
Do Until ActiveCell.Row > myLastRow
If ActiveCell.Value <> ActiveCell.Offset(-1, 0).Value Then
ComboBox1.AddItem ActiveCell.Value
End If
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = False
End Sub
Private Sub ComboBox1_Change()
Dim myLastRow As Integer
Application.ScreenUpdating = False
Range("A2").Select
Selection.Sort Key1:=Range("A2"), Key2:=Range("B2"), Order1:=xlAscending, Order2:=xlAscending, Header:=xlYes
ComboBox2.Clear
myLastRow = Range("a65000").End(xlUp).Row
Range("A2").Select
Do Until ActiveCell.Value = ComboBox1.Value
ActiveCell.Offset(1, 0).Select
Loop
Do Until ActiveCell.Value <> ComboBox1.Value
If ActiveCell.Offset(0, 1).Value <> ActiveCell.Offset(-1, 1).Value _
Or ActiveCell.Offset(0, 0).Value <> ActiveCell.Offset(-1, 0).Value Then
ComboBox2.AddItem ActiveCell.Offset(0, 1).Value
End If
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = False
End Sub
Private Sub ComboBox2_Change()
Dim myLastRow As Integer
Do Until ActiveCell.Value <> ComboBox2.Value
If ActiveCell.Offset(0, 1).Value <> ActiveCell.Offset(-1, 1).Value _
Or ActiveCell.Offset(0, 0).Value <> ActiveCell.Offset(-1, 0).Value Then
ComboBox2.AddItem ActiveCell.Offset(0, 1).Value
End If
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = False
Bookmarks