I'm completely new new to excel vba. I've been trying to create an excel userform with 3 dependent comboboxes. I was able to follow a tutorial and finish up to the 2nd combobox. I couldn't find any tutorial which explains how to get to the 3rd combobox. I tried to do on my own, but my results ended up with the items in combobox2 showing up in combobox3 as well, which is not what I need. I think I'm messing it with case selection ( I have no idea what I'm doing). The first two boxes work fine, but when the case numbers of the last combobox increase, it gets messed up. Here's the vba code. How do I proceed from here to make the 3rd one dependent on the 2nd combobox?
VBA Code:
Private Sub ComboBox1_Change()
Dim index As Integer
index = ComboBox1.ListIndex
ComboBox2.Clear
Select Case index
Case Is = 0
With ComboBox2
.AddItem "CAT 1"
.AddItem "CAT 2"
.AddItem "CAT 3"
End With
Case Is = 1
With ComboBox2
.AddItem "CAT 4"
.AddItem "CAT 5"
End With
Case Is = 2
With ComboBox2
.AddItem "CAT 6"
.AddItem "CAT 7"
.AddItem "CAT 8"
.AddItem "CAT 9"
End With
Case Is = 3
With ComboBox2
.AddItem "CAT 10"
End With
Case Is = 4
With ComboBox2
.AddItem "CAT 11"
.AddItem "CAT 12"
End With
Case Is = 5
With ComboBox2
.AddItem "CAT 13"
End With
Case Is = 6
With ComboBox2
.AddItem "CAT 15"
End With
Case Is = 7
With ComboBox2
.AddItem "CAT 16"
End With
End Select
End Sub
Private Sub ComboBox2_Change()
Dim index As Integer
index = ComboBox2.ListIndex
ComboBox3.Clear
Select Case index
Case Is = 0
With ComboBox3
.AddItem "CAT 1 PART 0"
End With
Case Is = 1
With ComboBox3
.AddItem "CAT 1 PART 1"
.AddItem "CAT 1 PART 2"
.AddItem "CAT 1 PART 3"
.AddItem "CAT 1 PART 4"
.AddItem "CAT 1 PART 5"
.AddItem "CAT 1 PART 6"
.AddItem "CAT 1 PART 7"
.AddItem "CAT 1 PART 8"
.AddItem "CAT 1 PART 9"
.AddItem "CAT 1 PART 10"
.AddItem "CAT 1 PART 11"
End With
Case Is = 2
With ComboBox3
.AddItem "CAT 1 PART 12"
.AddItem "CAT 1 PART 13"
.AddItem "CAT 1 PART 14"
.AddItem "CAT 1 PART 15"
.AddItem "CAT 1 PART 16"
.AddItem "CAT 1 PART 17"
.AddItem "CAT 1 PART 18"
.AddItem "CAT 1 PART 19"
.AddItem "CAT 1 PART 20"
.AddItem "CAT 1 PART 21"
.AddItem "CAT 1 PART 22"
.AddItem "CAT 1 PART 23"
.AddItem "CAT 1 PART 24"
.AddItem "CAT 1 PART 25"
End With
Case Is = 3
With ComboBox3
.AddItem "CAT 1 PART 25"
.AddItem "CAT 1 PART 26"
.AddItem "CAT 1 PART 27"
.AddItem "CAT 1 PART 28"
.AddItem "CAT 1 PART 29"
.AddItem "CAT 1 PART 30"
.AddItem "CAT 1 PART 31"
.AddItem "CAT 1 PART 32"
.AddItem "CAT 1 PART 33"
.AddItem "CAT 1 PART 34"
.AddItem "CAT 1 PART 35"
.AddItem "CAT 1 PART 36"
End With
End Select
End Sub
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "MAIN 1"
.AddItem "MAIN 2"
.AddItem "MAIN 3"
.AddItem "MAIN 4"
.AddItem "MAIN 5"
.AddItem "MAIN 6"
.AddItem "MAIN 7"
.AddItem "MAIN 8"
End With
End Sub