ComboBox Problems

G

Guest

Hi everyone,
I made a userform that has some option buttons and two comboboxes. The user
choses from the two groups of option buttons and then goes to the first
combobox. I want the information in the second combobox to change depending
on what the person choses from the first combobox. I am having some problems.
It works well the first time but if the user changes their mind (i.e. choses
something else in the first combobox) the second combobox does not respond.
It clears and no new information is put in
Here is my code

COMMANDBUTTON3 ACTIVATES THE CHANGING OF COMBOBOX2, DEPENDING ON COMBOBOX1
INFORMATION

Private Sub CommandButton3_Click()
If Why.ComboBox1.Text = "-KAJ" Then
Why.ComboBox2.Clear
'Filling second combobox
Dim j As Integer
j = 2
Do Until IsEmpty(Cells(4, j))
prod = Workbooks("specs.xls").Worksheets("ProductIdentity").Cells(4, j)
Why.ComboBox2.AddItem (prod)
j = j + 1
Loop
ActiveWorkbook.Sheets("Blank").Select
End If
If Why.ComboBox1.Text = "-AA" Then
'Filling second combobox
Why.ComboBox2.Clear
Dim k As Integer
k = 2
Do Until IsEmpty(Cells(2, k))
prod = Workbooks("specs.xls").Worksheets("ProductIdentity").Cells(2, k)
Why.ComboBox2.AddItem (prod)
k = k + 1
Loop
ActiveWorkbook.Sheets("Blank").Select
End If
End Sub

Thanks for any help
 
T

Tom Ogilvy

Private Sub CommandButton3_Click()
If Why.ComboBox1.Text = "-KAJ" Then
Why.ComboBox2.Clear
'Filling second combobox
Dim j As Integer
j = 2
With Workbooks("specs.xls").Worksheets("ProductIdentity")
Do Until IsEmpty(.Cells(4, j))
prod = .Cells(4, j)
Why.ComboBox2.AddItem (prod)
j = j + 1
Loop
End With
ActiveWorkbook.Sheets("Blank").Select
ElseIf Why.ComboBox1.Text = "-AA" Then
'Filling second combobox
Why.ComboBox2.Clear
Dim k As Integer
k = 2
With Workbooks("specs.xls").Worksheets("ProductIdentity")
Do Until IsEmpty(.Cells(2, k))
prod = .Cells(2, k)
Why.ComboBox2.AddItem (prod)
k = k + 1
Loop
End With
ActiveWorkbook.Sheets("Blank").Select
End If
End Sub

The macro is triggered by a change in the value of Combobox3.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top