View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
KL KL is offline
external usenet poster
 
Posts: 201
Default Populate a Combobox from range.

Hi,

You can normally populate a combobox from range using the following
instruction:

ComboBox1.List=Range("A2:A10")

However, if you want to remove dups, you could try this code:

Private Sub UserForm_Initialize()
Dim c As Range, D As Object
Set D = CreateObject("Scripting.Dictionary")
For Each c In Sheets("Sheet1").Range("A2:A10")
If Not D.Exists(c.Value) Then D.Add c.Value, 1
Next c
ComboBox1.List = Application.Transpose(D.Keys)
End Sub

Regards,
KL


"ex1302" wrote in
message ...

Hi all,

Firstly, how can I populate a combobox on a userform from range on
sheet1 using vba, lets say "A2:A4".

Secondly, if this range contains duplicate values how can i "groupby"
to produce a non dupliacted list of values for the combobox.

Regards,

Andy


--
ex1302
------------------------------------------------------------------------
ex1302's Profile:
http://www.excelforum.com/member.php...o&userid=25217
View this thread: http://www.excelforum.com/showthread...hreadid=389308