Dependent Active X Combo Boxes

Alm5423

New Member
Joined
Sep 22, 2021
Messages
14
Office Version
  1. 2016
Platform
  1. Windows
Hey Everyone!

I'm trying to create a form with multiple Active X combo boxes where the selection in Combo Box 3 determines the list of drop down items in Combo Box 4.

Right now, Combo box 3 has two options: Type 1 or Type 2. If Type 1 is selected, I need Combo Box 4 (which currently contains a list of 8 items) to only show the first four that are related to Type 1. If Type 2 is selected, I need it to only show the second four options that are related to Type 2.

Does anyone know a VBA code that would allow me to do this? All of my Combo Box 4 drop down options are currently stored in a second tab on my worksheet.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
How about something like
VBA Code:
Private Sub ComboBox3_Click()
   Select Case Me.ComboBox3.Value
      Case "Type 1": Me.ComboBox4.List = Sheets("Lists").Range("A2:A5").Value
      Case "Type 2": Me.ComboBox4.List = Sheets("Lists").Range("A6:A9").Value
   End Select
End Sub
 
Upvote 0
Gave that a try. For some reason, I keep getting a "permission denied" error. The only thing I changed from your code above was swapping "Lists" for "Sheet 2" since that's the current name for my second tab.
 
Upvote 0
Gave that a try. For some reason, I keep getting a "permission denied" error. The only thing I changed from your code above was swapping "Lists" for "Sheet 2" since that's the current name for my second tab.
Found the problem! I had previously populated the "List Fill Range" for Combo box 4 when I was planning to do this a different way. Once I removed that and used your formula above, it worked perfectly! Thank you so much!
 
Upvote 0
Is there a way to add a third case for when Combo box 3 is blank? I essentially want to make it so that if Combo Box 3 is not filled out, there are no drop down options showing in Combo Box 4.
 
Upvote 0
Try using the change event instead like
VBA Code:
Private Sub ComboBox3_Change()
   Select Case Me.ComboBox3.Value
      Case "Type 1": Me.ComboBox4.List = Sheets("Lists").Range("A2:A5").Value
      Case "Type 2": Me.ComboBox4.List = Sheets("Lists").Range("A6:A9").Value
      Case "": Me.ComboBox4.Clear
   End Select
End Sub
 
Upvote 0
Try using the change event instead like
VBA Code:
Private Sub ComboBox3_Change()
   Select Case Me.ComboBox3.Value
      Case "Type 1": Me.ComboBox4.List = Sheets("Lists").Range("A2:A5").Value
      Case "Type 2": Me.ComboBox4.List = Sheets("Lists").Range("A6:A9").Value
      Case "": Me.ComboBox4.Clear
   End Select
End Sub
Brilliant, that's much better. Last question. Let's say someone selects Type 1 in Combo Box 3 and chooses one of their drop menu options in Combo Box 4...but then decides they need to switch Combo Box 3 to Type 2 (or blank). Is there a way to clear Combo Box 4 anytime Combo Box 3 is changed after the initial selection? I hope that makes sense!
 
Upvote 0
Yup, you can use this
VBA Code:
Private Sub ComboBox3_Change()
   Me.ComboBox4.Clear
   Select Case Me.ComboBox3.Value
      Case "Type 1": Me.ComboBox4.List = Sheets("Lists").Range("A2:A5").Value
      Case "Type 2": Me.ComboBox4.List = Sheets("Lists").Range("A6:A9").Value
   End Select
End Sub
 
Upvote 0
Solution
Yup, you can use this
VBA Code:
Private Sub ComboBox3_Change()
   Me.ComboBox4.Clear
   Select Case Me.ComboBox3.Value
      Case "Type 1": Me.ComboBox4.List = Sheets("Lists").Range("A2:A5").Value
      Case "Type 2": Me.ComboBox4.List = Sheets("Lists").Range("A6:A9").Value
   End Select
End Sub
That's the one I needed! Thank you!!
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,492
Members
448,967
Latest member
visheshkotha

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