Dependent Active X Combo Boxes

Alm5423

New Member
Joined
Sep 22, 2021
Messages
9
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 to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,587
Office Version
  1. 365
Platform
  1. Windows
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
 

Alm5423

New Member
Joined
Sep 22, 2021
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
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.
 

Alm5423

New Member
Joined
Sep 22, 2021
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
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!
 

Alm5423

New Member
Joined
Sep 22, 2021
Messages
9
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,587
Office Version
  1. 365
Platform
  1. Windows
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
 

Alm5423

New Member
Joined
Sep 22, 2021
Messages
9
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

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!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,587
Office Version
  1. 365
Platform
  1. Windows
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
 
Solution

Alm5423

New Member
Joined
Sep 22, 2021
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
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!!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,587
Office Version
  1. 365
Platform
  1. Windows
Glad to help & thanks for the feedback.
 

Forum statistics

Threads
1,147,477
Messages
5,741,360
Members
423,657
Latest member
Medrok2021

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