List of Different Cells

F

ForSale

In sheet1.range("b:b") I have a list of numbers. Some of the numbers
will repeat, some won't. In userform1.combobox1 I want to list all of
the different numbers (no repeats) from sheet1.range("b:b"). What is
the easiest way to do this?

Big Thanks.
 
J

jindon

try

Code:
--------------------

Private Sub UserForm_Initialize()
Dim dic As Object, a, e
Set dic = CreateObject("scripting.dictionary")
dic.comparemode = vbTextCompare
With Sheets("Sheet1")
a = .Range("b1",.Range("b" & Rows.Count).End(xlUp)).Value
End With
For Each e In a
If Not IsEmpty(e) And Not dic.exists(e) Then dic.add e, Nothing
Next
If dic.count < 1 Then Exit Sub
Me.ListBox1.List = dic.keys
Set dic = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top