Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Populate a Combobox from range.


Hi all,

Firstly, how can I populate a combobox on a userform from range o
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,

And

--
ex130
-----------------------------------------------------------------------
ex1302's Profile: http://www.excelforum.com/member.php...fo&userid=2521
View this thread: http://www.excelforum.com/showthread.php?threadid=38930

  #2   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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Populate a Combobox from range.


Thanks, it works great.....

can this be extended to work across two columns?

ie A1:B2

Regards,

And

--
ex130
-----------------------------------------------------------------------
ex1302's Profile: http://www.excelforum.com/member.php...fo&userid=2521
View this thread: http://www.excelforum.com/showthread.php?threadid=38930

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Populate a Combobox from range.


try

Code
-------------------

Private Sub UserForm_Initialize()
Dim dic As Object, x, r As Range
Set dic = CreateObject("Scripting.Dictionary")
With Sheets("sheet1")
For Each r In .Range("a2:a4")
If Not IsEmpty(r) And Not dic.exists(r.Value) Then
dic.Add r.Value, Nothing
End If
Next
End With
x = dic.keys
Me.ComboBox1.List() = x
Set dic = Nothing: Erase x
End Sub

-------------------

--
jindo
-----------------------------------------------------------------------
jindon's Profile: http://www.excelforum.com/member.php...fo&userid=1313
View this thread: http://www.excelforum.com/showthread.php?threadid=38930

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i populate a text box according to selection in combobox? Steve Excel Worksheet Functions 0 April 13th 06 12:40 PM
Populate combobox Pat Excel Programming 1 December 10th 04 05:33 PM
populate combobox with sheet names David Goodall Excel Programming 3 September 12th 04 12:37 PM
Populate a combobox Rory[_3_] Excel Programming 2 June 9th 04 04:20 PM
Populate Column Header on ComboBox michael_13143 Excel Programming 1 April 23rd 04 05:45 PM


All times are GMT +1. The time now is 07:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"