ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ComboBox Problems (https://www.excelbanter.com/excel-programming/339653-combobox-problems.html)

trini

ComboBox Problems
 
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

Tom Ogilvy

ComboBox Problems
 
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.

--
Regards,
Tom Ogilvy

"trini" wrote in message
...
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





All times are GMT +1. The time now is 10:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com