Is it possible to add a conditional to a combobox options? VBA

Asked

Viewed 492 times

-2

0

I am developing a form by VBA Userform and would like to generate a conditional on it.

I got two Combobox. The first allows choosing between only two cases, A and B. I would like the second to present a set of different options depending on the user’s choice of the first combobox, A or B.

Example: If the user chooses A in combobox 1, combobox 2 can be filled in with numbers 1 to 10. If you choose B in combobox 1, the combobox 2 can be filled in with numbers from 20 to 30.

1 answer

1


Ola Leandro follows the example. But I would like to warn you that this is a simple problem and ask you to take a little more time looking for the solution. It is very likely that this solution/question is closed to the detriment of being a code where not adc. the community. (make it clear I don’t speak for Stackoverflow) I hope you understand that I don’t want to point or criticize anyone, just a warning.

Best of luck to you!

Private Sub cmb_Set01_Change()
    cmb_Set02.Clear

    If cmb_Set01.Value = "A" Then
        cmb_Set02.AddItem "1"
        cmb_Set02.AddItem "2"
        cmb_Set02.AddItem "3"
        cmb_Set02.AddItem "4"
        cmb_Set02.AddItem "5"
    ElseIf cmb_Set01.Value = "B" Then
        cmb_Set02.AddItem "6"
        cmb_Set02.AddItem "7"
        cmb_Set02.AddItem "8"
        cmb_Set02.AddItem "9"
        cmb_Set02.AddItem "10"
    End If

End Sub

Private Sub UserForm_Initialize()

    cmb_Set01.AddItem "A"
    cmb_Set01.AddItem "B"

End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.