L
Liz
Hi,
I have two multi-select listboxes. The selections from ListBox 1 will
determine the and filter the available choices for Listbox 2.
I do have code that works when a combobox is used as the source to filter a
listbox. But I am not sure how I can modify it to accommodate a multi-select
listbox as the source.
Thanks for your help!
My code is below which works when a single select combo box is used as the
source:
Private Sub cboxProductLine_Change()
Dim myRng As Range
Dim myCell As Range
If Me.cboxProductLine.ListIndex < 0 Then
Me.lstProductFiltered.ListIndex = -1
End If
With Worksheets("LOVs")
Set myRng = .Range("ProductFilter") 'Using a dynamic named range
End With
'Clear list index if it already exists.
With lstProductFiltered
.Clear
End With
For Each myCell In myRng.Cells
If LCase(myCell.Value) = LCase(Me.cboxProductLine.Value) Then
Me.lstProductFiltered.AddItem myCell.Offset(0, 1).Value
End If
Next myCell
End Sub
I have two multi-select listboxes. The selections from ListBox 1 will
determine the and filter the available choices for Listbox 2.
I do have code that works when a combobox is used as the source to filter a
listbox. But I am not sure how I can modify it to accommodate a multi-select
listbox as the source.
Thanks for your help!
My code is below which works when a single select combo box is used as the
source:
Private Sub cboxProductLine_Change()
Dim myRng As Range
Dim myCell As Range
If Me.cboxProductLine.ListIndex < 0 Then
Me.lstProductFiltered.ListIndex = -1
End If
With Worksheets("LOVs")
Set myRng = .Range("ProductFilter") 'Using a dynamic named range
End With
'Clear list index if it already exists.
With lstProductFiltered
.Clear
End With
For Each myCell In myRng.Cells
If LCase(myCell.Value) = LCase(Me.cboxProductLine.Value) Then
Me.lstProductFiltered.AddItem myCell.Offset(0, 1).Value
End If
Next myCell
End Sub