PDA

View Full Version : Solved: ComboBox - Need Help!!!



ashnaveen
08-10-2006, 02:35 AM
Hi
I'm new to VBA coding. I have created a Userform with 2 ComboBox.
Let me call them as
cboPartA
cboPartB

While cboPartA takes the data from Row source, the cboPartB should check the selection in PartA and based on that select its data/ Row source.

For eg:
Assuming that there are 4 columns of data. Let's name them as
Phases
Phase-I
Phase-II
Phase-III

Now, in PartA Combobox I have data as 1,2,3...
So if I select 1, then the data in PartB combobox should be of Phase-I column. Similarly, if I select 2 in PartA, then the data in PartB combobox should be of Phase-II column and so on.
The user cannot select PartB if info is not selected in PartA.

It would be very grateful if anyone could help me in creating this part.

Thanks in advance
Ash

Bob Phillips
08-10-2006, 03:24 AM
Add this code to cboPartA click event



Select Case cbpoPartA.Value
Case 1: cboPartB.Rowsource = Range("Phase-I").Address(, , , True)
Case 2: cboPartB.Rowsource = Range("Phase-II").Address(, , , True)
Case 3: cboPartB.Rowsource = Range("Phase-III").Address(, , , True)
End Select

ashnaveen
08-10-2006, 03:45 AM
thanks for that quick reply xld.

I did try the code. But it didnt work.


Private Sub cboPartB_Change()
If cboPartA.Value = "abc" Then
cboPartB.RowSource = Range("a_d").Address(, , , True)
End If
End Sub


But even this didnt work.

Is there any other option.

Ash

Bob Phillips
08-10-2006, 04:22 AM
I did have a typo, and I had to test it with names of Phase_I, Phase_II etc. as hypehns threw an invalid name, but this worked for me



Select Case cboPartA.Value
Case 1: cboPartB.Rowsource = Range("Phase_I").Address(, , , True)
Case 2: cboPartB.Rowsource = Range("Phase_II").Address(, , , True)
Case 3: cboPartB.Rowsource = Range("Phase_III").Address(, , , True)
End Select

ashnaveen
08-10-2006, 05:06 AM
Hi
I did try your code. But it doesnt seem to be working for me. Really wonder where I might be going wrong.
I have attached the working file. Pl help me with this.

Thanks a ton for your help!!! Really appreciate this.

Ash

ashnaveen
08-10-2006, 06:10 AM
Here's my updated version of the working file.
When I give a cell value, it works. But when try with Range name or a Range itself, it doesnt work.

Pl help!!!

ashnaveen
08-10-2006, 06:11 AM
sorry!!!
Forgot to upload the file.

Here it is.

lucas
08-10-2006, 07:05 AM
Hi ashnaveen,
See attached file for an example of how to populate dependent comboboxes on a userform......just an example I dug up. Maybe you can take it from here and if you have more questions post back....

Bob Phillips
08-10-2006, 08:06 AM
This works fine



Private Sub cboPartA_Change()
Myval = Me.cboPartA.Value
Select Case Myval
Case "Phase 1"
Me.cboPartB.RowSource = Worksheets("Data").Range("c2:c5").Address(, , , True)
Case "Phase 2"
Me.cboPartB.RowSource = Worksheets("Data").Range("d2:d5").Address(, , , True)
Case "Phase 3"
Me.cboPartB.RowSource = Worksheets("Data").Range("hij").Address(, , , True)
End Select
End Sub

ashnaveen
08-11-2006, 12:29 AM
Hey,
It worked!!!

Thanks a ton for your help.

Ash