根据以前select的选项限制列表框中的项目
如何根据Excel用户窗体中以前select的选项来限制列表框中的字段选项?
例如,我们有这样的问题:
你想要水果还是蔬菜?
- Fruit - Vegetable
选一个:
- Apple - Orange - Lettuce - Cucumber
所以如果他们select水果,下一个问题/select应该限制只有苹果和橙子的select。 苹果和橙色是用户在select水果后应该看到的唯一select。
使用combobox代替列表框会更容易。 获得水果和蔬菜的“变化”事件,并相应填充另一个事件
Private Sub ComboBox_FruitsVegetables_Change() ComboBox_ChoosenFruitOrVegetable.Clear With ComboBox_ChoosenFruitOrVegetable If ComboBox_FruitsVegetables.Value = "Fruit" Then ' 1. If ComboBox_FruitsVegetables.Value = "Fruit" .AddItem ("my fruit") 'add items per fruit .Value = "my fruit" ElseIf ComboBox_FruitsVegetables = "Vegetables" Then ' 1. If ComboBox_FruitsVegetables.Value = "Fruit" .AddItem ("my veggy") 'add items per veggies .Value = "my veggy" End If ' 1. If ComboBox_FruitsVegetables.Value = "Fruit" End With End Sub
要将select限制为只有VBA添加的值,请转到combobox的“属性”窗口,然后select“样式2”。如果由于允许多个select而有一个列表框,请告诉我 – 我没有想到这一点文中问“select一个” – 。