Easy VBA ComboBox Question - I Hope!


Posted by tracey newbie on February 12, 2002 3:06 PM

I have a form with 2 combo boxs - the first combobox's rowsource property is set to "sheet1!A1:A3" - If the user select the value corresponding to cell"A1" I want the contents of the second combo box to be "sheet1!B1:B3" and if the user selects the value corresponding to cell A2 I want the contents of the second combo box to change to "sheet1!C1:C3" etc..
I've tried

If Combobox1.Value = Range("A1").Value
Then
Combobox2.RowSource = Sheet1.Range(B1,B3)
End If

Pretty poor attempt I know!!!

Posted by Juan Pablo G. on February 12, 2002 7:28 PM

Rowsource is a string, not a range object, so, one (easy) way of doing this would be (Following your own code)

If Combobox1.Value = Range("A1").Value Then
Combobox2.RowSource = "Sheet1!B1:B3"
elseIf Combobox1.Value = Range("A2").Value
Combobox2.RowSource = "Sheet1!C1:C3"
else
Combobox2.RowSource = "Sheet1!D1:D3"
End If

Or even better, a Select Case

Select Case ComboBox1.Value
Case Range("A1")
Combobox2.RowSource = "Sheet1!B1:B3"
Case Range("A2")
Combobox2.RowSource = "Sheet1!C1:C3"
Case Range("A3")
Combobox2.RowSource = "Sheet1!D1:D3"
End Select

Juan Pablo G.



Posted by trcey newbie on February 14, 2002 8:28 AM

THANK YOU - YOU'RE A STAR!!!!!!