How do I add a third dependent combobox in excel VBA?

ibruzzi

New Member
Joined
Jun 25, 2021
Messages
22
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,162
Office Version
  1. 365
Platform
  1. Windows
Judging by your new thread I take it that this has been resolved?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,162
Office Version
  1. 365
Platform
  1. Windows

Forum statistics

Threads
1,140,925
Messages
5,703,205
Members
421,280
Latest member
Jaycee01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top