We know how to fill or transfer data from an Excel worksheet to a listbox from our previous videos. But how do we fill a listbox on Excel userform with unique values from a worksheet?
We use a 'collection' object. A collection can hold a lot of data in one variable. It has four methods and the Add method looks like this
Collection.Add item, [key], [before], [after]
The key value has to be unique. Now you assign the same value to the key and the item. So no duplicate values can be added. Every time VBA encounters a duplicate value it generates an error. We choose to ignore the errors by using 'On error resume next' line of code and achieve our goal of not adding any duplicate values to our listbox.
Important thing to notice is that you convert the key value into a string.
You can find some more details here:
https://www.exceltrainingvideos.com/h...