I got my second ActiveX comboBox to populate based on the 1st comobox selection but now I need only unique values to show in Combobox#2
Here is my code for filling combobox2
I modified it some based on the parts in my code on my first combobox that fills it with unique items only but now It only gives one item in combobox 2 and not multiple unique items based on the selection in combobox 1.
any sugestions?
Here is my code for filling combobox2
Code:
[TABLE]
<colgroup><col style="width:74pt" span="2" width="99"> </colgroup><tbody>[TR]
[TD="width: 198, colspan: 2"]Private Sub cmbRent_change()[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"] MyVal = Me.cmbRent.Value[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"] 'loop thru col B[/TD]
[/TR]
[TR]
[TD="colspan: 2"] lr = ThisWorkbook.Sheets("DATA").Cells(Rows.Count, 1).End(xlUp).Row[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"] 'clear cmbSub[/TD]
[/TR]
[TR]
[TD="colspan: 2"] ThisWorkbook.Sheets("CHART").cmbSub.Clear[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD][/TD]
[/TR]
[TR]
[TD] [/TD]
[TD][/TD]
[/TR]
[TR]
[TD] 'loop thru[/TD]
[TD][/TD]
[/TR]
[TR]
[TD] For x = 2 To lr[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"] If MyVal = ThisWorkbook.Sheets("DATA").Cells(x, 1) Then[/TD]
[/TR]
[TR]
[TD="colspan: 2"] 'add to combobox[/TD]
[/TR]
[TR]
[TD="colspan: 2"] ThisWorkbook.Sheets("CHART").cmbSub.AddItem ThisWorkbook.Sheets("DATA").Cells(x, 2)[/TD]
[/TR]
[TR]
[TD] End If[/TD]
[TD][/TD]
[/TR]
[TR]
[TD] [/TD]
[TD][/TD]
[/TR]
[TR]
[TD] Next x[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"] ThisWorkbook.Sheets("CHART").cmbSub.ListIndex = -1[/TD]
[/TR]
[TR]
[TD] End Sub[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I modified it some based on the parts in my code on my first combobox that fills it with unique items only but now It only gives one item in combobox 2 and not multiple unique items based on the selection in combobox 1.
Code:
Private Sub cmbRent_change()
MyVal = Me.cmbRent.Value
'loop thru col B
lr = ThisWorkbook.Sheets("DATA").Cells(Rows.Count, 1).End(xlUp).Row
'loop thru
For x = 2 To lr
If MyVal = ThisWorkbook.Sheets("DATA").Cells(x, 1) Then
If ThisWorkbook.Sheets("DATA").Cells(x, 2) <> "" And (InStr(blah, "|" & ThisWorkbook.Sheets("DATA").Cells(x, 2) & "|") = 0) Then
If FirstTime = True Then
FirstTime = False
blah = "|" & blah & ThisWorkbook.Sheets("DATA").Cells(x, 2) & "|"
Else
blah = blah & ThisWorkbook.Sheets("DATA").Cells(x, 2) & "|"
End If
End If
'Clear cmbSub
ThisWorkbook.Sheets("CHART").cmbSub.Clear
'add to combobox
ThisWorkbook.Sheets("CHART").cmbSub.AddItem ThisWorkbook.Sheets("DATA").Cells(x, 2)
End If
Next x
myArray = Split(blah, "|")
For Each cell In myArray
If cell <> "" Then
ThisWorkbook.Sheets("CHART").cmbSub.AddItem ThisWorkbook.Sheets("DATA").Cells(x, 2)
End If
Next cell
ThisWorkbook.Sheets("CHART").cmbSub.ListIndex = -1
End Sub
any sugestions?