Hello
I try to populate data in listbox on form based on selected items from combobox1,combobox2
combobox1 will match with column A and combobox2 will match with column E then should populate data in list box
here is code getting from this forum and I modified based on my requirements.
I hope some body help me.
thanks
I try to populate data in listbox on form based on selected items from combobox1,combobox2
combobox1 will match with column A and combobox2 will match with column E then should populate data in list box
here is code getting from this forum and I modified based on my requirements.
VBA Code:
Private Sub CommandButton1_Click()
Dim i As Long, j As Long, k As Long
Dim cb1 As String
Dim cb2 As String
a = Sheets("Sheet3").Range("A1:F" & Sheets("Sheet3").Range("F" & Rows.Count).End(3).Row).Value
With ListBox2
.ColumnWidths = "40;50;50;40;60;40"
.columnCount = 6
.Font.Size = 10
End With
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
For i = 1 To UBound(a)
If ComboBox1.Value = "" Then cb1 = a(i, 1) Else cb1 = ComboBox1.Value
If ComboBox2.Value = "" Then cb2 = a(i, 5) Else cb1 = ComboBox2.Value
If LCase(a(i, 1)) Like LCase(cb1) & "*" And LCase(a(i, 5)) Like LCase(cb2) & "*" Then
k = k + 1
For j = 1 To 6
b(k, j) = a(i, j)
Next
End If
Next
If k > 0 Then ListBox2.List = b
If ListBox2.ListCount = 0 Then
MsgBox "doesn't show data"
End If
End Sub
thanks