Jill Gordon
June 29th, 2001, 04:39 AM
I am creating a visual basic program so that I can have connecting drop-down lists in my spreadsheet. My first two comboboxes work (these are for manufacturer and model). I have tried to add another combobox for registration number but it doesn't work. Can anyone tell me what is wrong with the program?
In my workbook it goes along the lines of:
Private Sub Workbook_Open()
Sheet1.ComboBox1.AddItem "Alfa Romeo", 0
Sheet1.ComboBox1.AddItem "Aston Martin", 1 ...etc
Sheet 1.ComboBox1.ListIndex = 0
End Sub
My program for sheet 1 looks like this:
Private Sub ComboBox1.List(ComboBox1.ListIndex) = "Alfa Romeo" Then
ComboBox2.AddItem "145", 0
ComboBox2.AddItem "146", 1 ...etc
ElseIf ComboBox2.List(ComboBox2.ListIndex) = "Aston Martin" Then
ComboBox2.AddItem "DB7", 0
ComboBox2.AddItem "Lagonda", 1 ...etc
Else
MsgBox "There was a problem in ComboBox1_Click"
End If
ComboBox2.ListIndex = 0
End Sub
For sheet 3 my program looks like this:
Private Sub ComboBox2_Change()
ComboBox3.Clear
If ComboBox2.List(ComboBox2.ListIndex) = "145" Then
ComboBox3.AddItem "A", 0
ComboBox3.AddItem "B", 1 ...etc
Else
MsgBox "There was a problem in ComboBox2_Click"
End If
ComboBox3.ListIndex = 0
End Sub
In my workbook it goes along the lines of:
Private Sub Workbook_Open()
Sheet1.ComboBox1.AddItem "Alfa Romeo", 0
Sheet1.ComboBox1.AddItem "Aston Martin", 1 ...etc
Sheet 1.ComboBox1.ListIndex = 0
End Sub
My program for sheet 1 looks like this:
Private Sub ComboBox1.List(ComboBox1.ListIndex) = "Alfa Romeo" Then
ComboBox2.AddItem "145", 0
ComboBox2.AddItem "146", 1 ...etc
ElseIf ComboBox2.List(ComboBox2.ListIndex) = "Aston Martin" Then
ComboBox2.AddItem "DB7", 0
ComboBox2.AddItem "Lagonda", 1 ...etc
Else
MsgBox "There was a problem in ComboBox1_Click"
End If
ComboBox2.ListIndex = 0
End Sub
For sheet 3 my program looks like this:
Private Sub ComboBox2_Change()
ComboBox3.Clear
If ComboBox2.List(ComboBox2.ListIndex) = "145" Then
ComboBox3.AddItem "A", 0
ComboBox3.AddItem "B", 1 ...etc
Else
MsgBox "There was a problem in ComboBox2_Click"
End If
ComboBox3.ListIndex = 0
End Sub