Hello !
I am trying to fill a multi-column ListBox based on a selection on a ComboBox (being populated through RowSource property). I am having an issue because the code works but is only showing the first row of data found and not all of them. I believe its because its not in a loop, but not sure how to attack it. Here is my code:
Private Sub ComboBox1_Change()
Dim cName As Range
Dim clName As Range
Dim jName As Variant
clName = ComboBox1.Value
With Worksheets("BOM Route")
Set cName = .Columns("A")
End With
Set clName = cName.Find(What:=jName, _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not clName Is Nothing Then
ListBox1.AddItem
With ListBox1
.List(.ListCount - 1, 0) = clName.Offset(0, 1).Value 'Job Name B
.List(.ListCount - 1, 1) = clName.Offset(0, 8).Value 'Paper I
.List(.ListCount - 1, 2) = clName.Offset(0, 11).Value 'Envelope L
End With
Else
MsgBox jName & " not found in worksheet."
End If
End Sub
I am trying to fill a multi-column ListBox based on a selection on a ComboBox (being populated through RowSource property). I am having an issue because the code works but is only showing the first row of data found and not all of them. I believe its because its not in a loop, but not sure how to attack it. Here is my code:
Private Sub ComboBox1_Change()
Dim cName As Range
Dim clName As Range
Dim jName As Variant
clName = ComboBox1.Value
With Worksheets("BOM Route")
Set cName = .Columns("A")
End With
Set clName = cName.Find(What:=jName, _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not clName Is Nothing Then
ListBox1.AddItem
With ListBox1
.List(.ListCount - 1, 0) = clName.Offset(0, 1).Value 'Job Name B
.List(.ListCount - 1, 1) = clName.Offset(0, 8).Value 'Paper I
.List(.ListCount - 1, 2) = clName.Offset(0, 11).Value 'Envelope L
End With
Else
MsgBox jName & " not found in worksheet."
End If
End Sub