Hi
I have a user form with list box that displays a named range of data. In a combo box I select a string from a drop down list, once selected the list box filters the data on records with the string selected into an array and the array is set to the list box.
Works fine but I'm getting blanks for the records which don't match. Code for the combo box selection is below, lstGatePrices is the list box, gate_information contains the source data which is removed once the button is selected (lstGatePrices.RowSource=""), images pre and post selection are also include, any help appreciated. Basically I want to filter a list from a combo box, I also want to filter further on more columns but that can come later. Thanks
Private Sub cmbModel_Change()
Dim out As String, out2 As String
Dim iCount As Integer
Dim arr As Variant
Dim rg As Range
Dim i As Long, j As Long, row As Long
Dim vDataArray(1 To 200, 1 To 6)
On Error Resume Next
lstGatePrices.RowSource = ""
Set rg = Worksheets("gate_information").Range("A1").CurrentRegion
row = 2
For i = 1 To rg.Rows.Count
If rg.Cells(i, 1) = Me.cmbModel.Value Then
For j = 1 To 6
vDataArray(i, j) = rg.Cells(i, j)
out2 = out2 & " " & rg.Cells(i, j)
Next j
End If
Next i
lstGatePrices.List = vDataArray
MsgBox "bob " & Me.cmbModel.Value & " " & Me.lstGatePrices.ColumnCount & " " & Me.lstGatePrices.ListCount & " " & out & " out2 " & out2
End Sub
Bookmarks