Populate a list box with visible unique values from an excel table (vba)
Excel tables, introduced in excel 2007, sort, filter and organize data any way you like. You can also format data and choose from many professional looking styles.
In this vba tutorial I will show you how to populate a list box with unique visible values from an excel table.

Instructions
- Sort or/and filter the table.
- Press "Populate list box" button.
Only unique visible values from Column1 are added to the list box.
VBA code
Sub FilterUniqueData()
Dim Lrow As Long, test As New Collection, i As Single
Dim Value As Variant, temp As Range
On Error Resume Next
Set temp = Worksheets("Sheet1").ListObjects("Table1").ListColumns(1).Range
For i = 2 To temp.Cells.Rows.Count
If Len(temp.Cells(i)) > 0 And Not temp.Cells(i).EntireRow.Hidden Then
test.Add temp.Cells(i), CStr(temp.Cells(i))
End If
Next i
Worksheets("Sheet1").Shapes("List Box 1").ControlFormat.RemoveAllItems
For Each Value In test
Worksheets("Sheet1").Shapes("List Box 1").ControlFormat.AddItem Value
Next Value
Set test = Nothing
End SubDownload excel 2007 MacroEnabled *.xlsm file
Related posts:
Excel vba: Populate a combobox with values from a pivot table
Excel vba: Populate a combo box (form control)
Vlookup visible data in a table and return multiple values in excel
Count unique and duplicates text values in a closed workbook in excel (formula)
Extract unique distinct values from a filtered table (udf and array formula)

















I have searched relentlessly for the answer to this question. How can I get the listbox to return the unique value but include the corresponding column 3 in your excample? I have a product list that has Kit and Lot number. I want the unique Kit but the correspoinding lot number for the kit with description.