Removing items from activex combo boxes.

Ancient Wolf

Board Regular
Joined
Mar 17, 2009
Messages
89
Asking for help again with Excel 2007

I am creating a spreadsheet that will use 5 combo boxes. Each selection in a combo box will affect the next one in line and change the available options. Using the coding below:

Private Sub ComboBox1_Change()
With ComboBox2
Select Case ComboBox1.Value
Case "Fruit"
.AddItem "apple"
.AddItem "orange"
Case "Vegetable"
.AddItem "brocoli"
End Select
End With
End Sub

I understand how to get the different combo boxes to change selections. However, I also need the items to be removed in case someone clicks the wrong choice and tries to go back to pick the correct one. I am currently trying to get the codes to remove the items added in by the .additem lines by using the .removeitem code or the .removeallitems code, but I keep running into errors. I can get one item to remove by doing it this way:
Case "Fruit"
.AddItem "apple"
.AddItem "orange"
Case "Vegetable"
.removeitem (1 / 2)
.AddItem "brocoli"
It will remove apple, but if I try to add a second remove line, or try to use the removeall, then I get a run error. Can anyone tell me what I am doing wrong?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,215,556
Messages
6,125,495
Members
449,235
Latest member
Terra0013

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