带有依赖组合框的组合框多选下拉列表

时间:2018-10-08 08:46:36

标签: excel vba excel-vba

我有一个用户窗体,希望用户可以选择多个选项,但是在寻找最佳方法时遇到了一些问题。如果使用combobox1,则似乎无法允许多个选择和Checkbox Option。我还想根据combobox1中的选择填充Combobox2。

我正在尝试以下代码:

Private Sub UserForm_Initialize()
    Me.cbota1.AddItem "2A"
    Me.cbota1.AddItem "3Q"
    Me.cbota1.AddItem "Sim"
    Me.cbota1.AddItem "2T"
End Sub

Private Sub cbota1_Change()
    Dim index As Integer
    index = cbota1.ListIndex
    cbota2.Clear
    Select Case index
        Case Is = 0
            With cbota2
                .AddItem "Add dime"
                .AddItem "Add annot"
                .AddItem "Others"
                txtTo.Value = "AXA"
            End With

        Case Is = 1
            With cbota2
                .AddItem "Modify"
                .AddItem "Reduce"
                .AddItem "Others"
                txtTo.Value = "CA"
            End With
        Case Is = 2
            With cbota2
                .AddItem "Lin"
                .AddItem "Non"
                .AddItem "Mul"
                .AddItem "Vi"
                txtTo.Value = "ABA"
            End With
        Case Is = 3
            With cbota2
                .AddItem "Ad"
                .AddItem "Red"
                txtTo.Value = "A"
            End With      
    End Select
End Sub

1 个答案:

答案 0 :(得分:0)

我能想到的一种解决方案,可能是过大的杀伤力,是当您单击Label或TextBox时打开第二个UserForm。然后,在新的用户窗体中,您可以列出可以在复选框中选择的所有项目,并允许用户从中进行选择。

我曾经短暂地考虑过一次,但是由于在用户窗体和模块之间传递选择的困难而决定不这样做。