Multiple Dependent ComboBoxes in UserForm

ddhsock

New Member
Joined
Jan 13, 2020
Messages
27
Office Version
  1. 365
Platform
  1. Windows
I have been trying to build a user form with dependent ComboBoxes. I have successfully created two but I cannot get the third to work. Here is the code for the first two that works.

VBA Code:
Private Sub ComboBox1_Change()

    Application.EnableEvents = False

    ComboBox2.Clear

    Application.EnableEvents = True

  

    Select Case ComboBox1.Value

        Case "Blocking"

            ComboBox2.AddItem "Roof Edge"

            ComboBox2.AddItem "Toilet Acc/Partition"

            ComboBox2.AddItem "Millwork"

            ComboBox2.AddItem "Door Frames"

            ComboBox2.AddItem "Chalkboards"

            ComboBox2.AddItem "Misc."

        Case "Framing"

            ComboBox2.AddItem "Walls"

            ComboBox2.AddItem "Joist"

            ComboBox2.AddItem "Roofs"

            ComboBox2.AddItem "Ceilings"

            ComboBox2.AddItem "Platforms"

            ComboBox2.AddItem "Accessories"

            ComboBox2.AddItem "Stairs"

        Case "Bolts"

            ComboBox2.AddItem "Wedge/Expansion"

            ComboBox2.AddItem "Machine"

        Case "Furring"

            ComboBox2.AddItem "Floor Furring"

            ComboBox2.AddItem "Wall Furring"

      

        End Select

   

 

          

   

          

  

End Sub

Here is code for the third ComboBox that I cannot get to run. I will also be needing to add additional ComboBoxes:
  Private Sub ComboBox2_Change()

    Application.EnableEvents = False

    ComboBox3.Clear

    Application.EnableEvents = True

        Case "Roof Edge"

            ComboBox3.AddItem "Bolted"

            ComboBox3.AddItem "Nailed"

            ComboBox3.AddItem "Shaped/Ripped"

        Case "Toilet Acc/Partition"

            ComboBox3.AddItem "Kiln Dried"

            ComboBox3.AddItem "Fire Treated"

        Case "Millwork"

             ComboBox3.AddItem "Kiln Dried"

            ComboBox3.AddItem "Fire Treated "

        Case "Door Frames"

ComboBox3.AddItem "Kiln Dried"

            ComboBox3.AddItem "Fire Treated

        Case "Chalkboards"

            ComboBox3.AddItem "Kiln Dried"

            ComboBox3.AddItem "Fire Treated

         Case "Misc."

ComboBox3.AddItem "Kiln Dried"

            ComboBox3.AddItem "Fire Treated          

        End Select

Any help would be appreciated,
 
Last edited by a moderator:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I'm glad to help you. Thanks for the feedback.

Hi,

I'm reopening the old thread as I'm facing a similar issue.
I'm using the comboboxes and a listbox to show possible combinations from a database stored in a different excel sheet.
After shamelessly copying your code, I'm facing this problem: If I move back and forward between the comboboxes and selecting different combinations, at some point, the dictionary used to held the possible values for the next combobox is empty. Adding the code for a combobox

VBA Code:
Private Sub ComboBox2_Change()
  Dim c As Range, dic As Object
  Set dic = CreateObject("Scripting.Dictionary")
  Dim database1(1 To 1000, 1 To 29)
  Dim My_range As Integer
  Dim i As Integer
  Dim column As Byte
 
  ComboBox3.Clear
  sh.Range("$A$1:$AD$115").AutoFilter field:=4
  ComboBox4.Clear
  sh.Range("$A$1:$AD$115").AutoFilter field:=8
  ComboBox5.Clear
  sh.Range("$A$1:$AD$115").AutoFilter field:=9
    
  
  For Each c In sh.Range("B2", sh.Range("B" & Rows.Count).End(xlUp))
    If c.Value = ComboBox1.Value And c.Offset(0, 1).Value = ComboBox2.Value Then
      dic(c.Offset(0, 2).Value) = Empty
    End If
  Next
  ComboBox3.List = dic.keys

  
  sh.Range("$A$1:$AD$115").AutoFilter field:=3, Criteria1:=Me.ComboBox2.Value

  For i = 2 To sh.Range("A100000").End(xlUp).Row
    If sh.Cells(i, 3) = Me.ComboBox2 Then
        My_range = My_range + 1
        For column = 1 To 12
        database1(My_range, column) = sh.Cells(i, column)
        Next column
     End If
  Next i
  
  Me.ListBox1.Clear
  UserForm2.ListBox1.List() = database1
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,084
Messages
6,128,721
Members
449,465
Latest member
TAKLAM

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