(Solved) – Adding items to a listbox from a selection in another listbox in excel vba

(solved)-–-adding-items-to-a-listbox-from-a-selection-in-another-listbox-in-excel-vba

What I’m looking to accomplish is to have a selection from a listbox (SelectHousingList) filter through a table in excel and come back with values in the same row but different column (much like the index/vlookup). Then display a list of choices with the same value in the first row and show the values in the second listbox (CatalystTypeList).

My code so far is as follows but nothing is showing up in the second listbox. I’m getting no error messages.

The first listbox has 9 values in the rows so I’m trying to use the listindex function in vb to lookup that value in the table in excel.

CatalystTypeList.Clear

lastrow1 = Sheet3.Cells(Rows.Count, 28).End(xlUp).Row

curVal = SelectHousingList.List(SelectHousingList.ListIndex, 6)

Dim dict2 As Object
Set dict2 = CreateObject("Scripting.Dictionary")
For x = 29 To lastrow1
If Worksheets("Catalyst 2020A1").Cells(x, "D") = curVal Then
    If Not dict.Exists(Worksheets("Catalyst 2020A1").Cells(x, "A").Value) Then
        Me.CatalystTypeList.AddItem Worksheets("Catalyst 2020A1").Cells(x, "A")
        dict(Worksheets("Catalyst 2020A1").Cells(x, "A").Value) = 1
    End If
End If
Next x

If you have any questions or would like more info don’t hesitate to ask.

Thank you for any/all help!!

Leave a Reply

Your email address will not be published. Required fields are marked *