Dependence combo boxes with each other

inactiveUser214710

Board Regular
Joined
Apr 27, 2012
Messages
171
Here I am again to ask for help
In a domestic project, I face a problem that I don't know how to solve it. Here's the question as an example:
I have a userform1 among other boxes, I have two combo boxes (cbo1; cbo2), by depending each other and that, will operate the opening of another userform2. In this userform2 I have just a combo box (cbo3) used for two different situations, that depending on of the instructions given by cbo1 and cbo2.
With this code below I am not getting that the cbo3 does not answer. Where the error will be.
Userform1:
Cbo1: BancA; BankB; BanKC
Cbo2: Débit; Credit, Others
Userform2
= If BankA (cbo1) and Débit(cbo2) => cbo3 open with (“A”; ”B”; ”C”);
= If BankA (cbo1) and Credit (cbo2) => cbo3 open with (“X”; ”W”; ”Y” )
= the same for BankB and BankC
VBA Code:
[B]' ================Code userform1======[/B]

Private Sub cbo1_Change()
  With cbo2
        .Clear
    Select Case cbo1.Value
        Case "BankA"
            cbo2.List = Array("Debit", "Credit")
        Case "BankB"
            cbo2.List = Array("Debit", "Credit")
        Case "BankC"
            cbo2.List = Array("Debit", "Credit")
    End Select
  End With

End Sub

Private Sub cbo2_Change()

'Why this instrutions don't appear?

With UserForm2.cbo3
   .Clear
       Select Case cbo2.Value
            Case "Debit"
                 UserForm2.Show
                 UserForm2.cbo3.List = Array("A", "B", "C")
            Case "Credit"
                 UserForm2.Show
                 UserForm2.cbo3.List = Array("X", "W", "Y")
       End Select
End With

End Sub

Private Sub UserForm_Initialize()

cbo1.List = Array("BankA", "BankB", "BankC")

End Sub
Thank you
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Whenever you are referring to a userform in your code .....
With UserForm2.cbo3
.... at that point the userform will be loaded. After a userform is loaded you can manage things as you like. The last statement should be the Show method, because after that your userform is on the screen and waiting for user input. So change your code:
VBA Code:
With UserForm2
   .cbo3.Clear
   Select Case cbo2.Value
        Case "Debit"
             .cbo3.List = Array("A", "B", "C")
        Case "Credit"
             .cbo3.List = Array("X", "W", "Y")
   End Select
   .Show
End With
Note that the objects with the preceding dots refer to UserForm2 due to the "With" statement.
 
Upvote 0
You are welcome. Glad it works.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,492
Members
448,967
Latest member
visheshkotha

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