Avoiding two or more comboboxes having same selection at a time vba

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
I have five comboboxes in all.

One named cmbMain

The other four, cmb1 to cmb4

CmbMain is loaded with five items.

When I select the first item from cmbMain, I enable only cmb1.
When I select the second item, I enable both cmb1 and cmb2.
When I select the third and fourth items, I enable cmb1, cmb2 and cmb3.
When I select the fifth item, I enable all from cmb1 to cmb4.

Cmb1 to cmb4 are loaded with same items, say A, B, C, D.

My goal is to be able to avoid selecting same item in multiple comboboxes.

Can someone pull it up for me?

I can't seem to figure it out.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Assuming that your comboboxes are in a userform, try something like this to populate the list in Cmb2 after a selection has been made in Cmb1, then use similar for the remaining boxes.
VBA Code:
Private Sub Cmb1_Change()
With UserForm1
    .Cmb2.List = .Cmb1.List
    .Cmb2.RemoveItem (.Cmb1.ListIndex)
End With
End Sub

You will need to add a logical test to exit without populating if the box is not enabled.
 
Upvote 0
Assuming that your comboboxes are in a userform, try something like this to populate the list in Cmb2 after a selection has been made in Cmb1, then use similar for the remaining boxes.
VBA Code:
Private Sub Cmb1_Change()
With UserForm1
    .Cmb2.List = .Cmb1.List
    .Cmb2.RemoveItem (.Cmb1.ListIndex)
End With
End Sub

You will need to add a logical test to exit without populating if the box is not enabled.


Okay. Got it, loud and clear.

I really appreciate that.

Have a nice time
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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