bemcbride

New Member
Joined
May 21, 2012
Messages
47
I'm creating a dependent drop down box using ComboBoxs. I have a total of 3 boxes dependent upon the previous. I've written the below so far but it's not working. When I select the item in the 2 drop down it doesn't appear in the drop down. Or (If i take out the .clear from below) the list expands to include all the items previously selected. AND I still cannot get the last box to work.

I've been working on this stupid thing for a couple days now and my brain is about to explode lol:ROFLMAO::eek:

PS as you can tell when I get to the last button I didn't actually put the options I'm just trying to at least get it to work.






Code:
Private Sub ComboBox3_Change()


With ComboBox3


.AddItem "Division A: Agriculture, Forestry, And Fishing"
.AddItem "Division B: Mining"
.AddItem "Division C: Construction"




End With


 
End Sub






Private Sub ComboBox4_Change()
Dim index As Integer
index = ComboBox3.ListIndex

ComboBox4.clear


Select Case index
    Case Is = 0
        With ComboBox4
        .Clear
            .AddItem "Major Group 01: Agricultural Production Crops"
            .AddItem "Major Group 02: Agriculture production livestock and animal specialties"
            .AddItem "Major Group 07: Agricultural Services"
            .AddItem "Major Group 08: Forestry"
            .AddItem "Major Group 09: Fishing, hunting, and trapping"
        End With
        
    Case Is = 1
        With ComboBox4
        .Clear
            .AddItem "Major Group 10: Metal Mining"
            .AddItem "Major Group 12: Coal Mining"
            .AddItem "Major Group 13: Oil And Gas Extraction"
            .AddItem "Major Group 14: Mining And Quarrying Of Nonmetallic Minerals, Except Fuels"
        End With
        
    Case Is = 2
        With ComboBox4
        .Clear
            .AddItem "Major Group 15: Building Construction General Contractors And Operative Builders"
            .AddItem "Major Group 16: Heavy Construction Other Than Building Construction Contractors"
            .AddItem "Major Group 17: Construction Special Trade Contractors"
        End With
        End Select
        
End Sub


Private Sub ComboBox5_Change()
Dim index As Integer
index = ComboBox4.ListIndex


ComboBox5.Clear


Select Case index
    Case Is = 0
        With ComboBox5
            .AddItem "last1"
        
        End With
        
    Case Is = 1
        With ComboBox5
            .AddItem "test2"
      
        End With
        
    Case Is = 2
        With ComboBox5
            .AddItem "boom3"
         
        End With
        End Select
End Sub
 
Last edited by a moderator:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
The code that populates the dependent combobox goes in the parent combobox's event procedure.

So if ComboBox4 is dependent on ComboBox3, then put this in ComboBox3_Change procedure.

Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] ComboBox[COLOR=#ff0000]3[/COLOR]_Change()
    [COLOR=darkblue]With[/COLOR] ComboBox4
        .Clear
        [COLOR=darkblue]Select[/COLOR] [COLOR=darkblue]Case[/COLOR] ComboBox3.ListIndex
            [COLOR=darkblue]Case[/COLOR] 0
                .AddItem "Major Group 01: Agricultural Production Crops"
                .AddItem "Major Group 02: Agriculture production livestock and animal specialties"
                .AddItem "Major Group 07: Agricultural Services"
                .AddItem "Major Group 08: Forestry"
                
            [COLOR=darkblue]Case[/COLOR] 1
                .AddItem "Major Group 10: Metal Mining"
                .AddItem "Major Group 12: Coal Mining"
                .AddItem "Major Group 13: Oil And Gas Extraction"
                .AddItem "Major Group 14: Mining And Quarrying Of Nonmetallic Minerals, Except Fuels"
                
            [COLOR=darkblue]Case[/COLOR] 2
                .AddItem "Major Group 15: Building Construction General Contractors And Operative Builders"
                .AddItem "Major Group 16: Heavy Construction Other Than Building Construction Contractors"
                .AddItem "Major Group 17: Construction Special Trade Contractors"
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Select[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Upvote 0
So instead of having the AddItems I'dd have that? But how will those items be listed? Do i add it afterward? I'm sorry I'm Confused.
 
Upvote 0
So instead of having the AddItems I'dd have that? But how will those items be listed? Do i add it afterward? I'm sorry I'm Confused.

What you had originally was the AddItems for ComboBox4 in Combobox4's procedure.

What you want is to move the AddItems for ComboBox4 to Combobox3's procedure. So when you change Combobox3, the code automatically updates Combobox4's list. That's it. You just put the Additems in the wrong procedure. The Additems for a dependent combobox (Combobox4 in this example), goes in the parent combobox's (Combobox3 in this example) procedure.
 
Upvote 0

Forum statistics

Threads
1,216,081
Messages
6,128,696
Members
449,464
Latest member
againofsoul

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
Back
Top