Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Distinct Data In Combo Box


Hi,

I have a range of data that i need to remain intact, i would like this
data to be presented in a combo box also...below is example data

A1
1
1
1
2
2
3
4
4

what i need is for the combo box to only list 1234, not 11122344..

Can anyone help ?

matt


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Distinct Data In Combo Box

Hi Matt

Here's a very quick and extremely dirty macro solution for range A1:A300 and Combobox1 in
Sheet1:

Sub Test()
Dim Coll As New Collection
Dim C As Range
Dim X As Variant
On Error Resume Next
For Each C In Range("A1:A300")
X = C.Text
If X < "" Then Coll.Add X, X
Next
Sheets(1).ComboBox1.Clear
For Each X In Coll
Sheets(1).ComboBox1.AddItem X
Next
Set Coll = Nothing
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"mattis2k" wrote in message
...

Hi,

I have a range of data that i need to remain intact, i would like this
data to be presented in a combo box also...below is example data

A1
1
1
1
2
2
3
4
4

what i need is for the combo box to only list 1234, not 11122344..

Can anyone help ?

matt


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Distinct Data In Combo Box

See John Walkenbach's site for sample code:

http://j-walk.com/ss/excel/tips/tip47.htm
Filling a ListBox With Unique Items

--
Regards,
Tom Ogilvy


"mattis2k" wrote in message
...

Hi,

I have a range of data that i need to remain intact, i would like this
data to be presented in a combo box also...below is example data

A1
1
1
1
2
2
3
4
4

what i need is for the combo box to only list 1234, not 11122344..

Can anyone help ?

matt


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Distinct Data In Combo Box

If we were talking about 30,000 rows I'd dispute the 'very quick'
claim <g. This slight amendment will give better performace:

Dim Coll As New Collection
Dim C As Range
Dim X As Variant
Sheets(1).ComboBox1.Clear
On Error Resume Next
For Each C In Range("A1:A300")
X = C.Text
If Len(X) = 0 Then
Coll.Add X, X
If Err.Number = 0 Then
Sheets(1).ComboBox1.AddItem
Else
Err.Clear
End If
End If
Next
On Error GoTo 0
Set Coll = Nothing


"Harald Staff" wrote in message ...
Hi Matt

Here's a very quick and extremely dirty macro solution for range A1:A300 and Combobox1 in
Sheet1:

Sub Test()
Dim Coll As New Collection
Dim C As Range
Dim X As Variant
On Error Resume Next
For Each C In Range("A1:A300")
X = C.Text
If X < "" Then Coll.Add X, X
Next
Sheets(1).ComboBox1.Clear
For Each X In Coll
Sheets(1).ComboBox1.AddItem X
Next
Set Coll = Nothing
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"mattis2k" wrote in message
...

Hi,

I have a range of data that i need to remain intact, i would like this
data to be presented in a combo box also...below is example data

A1
1
1
1
2
2
3
4
4

what i need is for the combo box to only list 1234, not 11122344..

Can anyone help ?

matt


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Distinct Data In Combo Box

....and the better performance isn't due to me getting this line completely wrong:

If Len(X) = 0 Then

of course should be

If Len(X) 0 Then

Oops!


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Distinct Data In Combo Box

"onedaywhen" skrev i melding
om...
If we were talking about 30,000 rows I'd dispute the 'very quick'
claim <g.


True. It was "quick" as in "fast written".

This slight amendment will give better performace:


Also true. That last For Each part was to demonstrate how to loop a
collection (for sorting purposes or whatever). Worth mentioning is that
collections are very quick and efficient, but they can be very memory
hungry.

Best wishes Harald
Followup to newsgroup only please


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
distinct count summarize Data for pivoit table mwyc Excel Discussion (Misc queries) 1 December 7th 09 01:44 PM
distinct andifak Excel Worksheet Functions 1 September 12th 07 01:42 PM
Extracting distinct data [email protected] Excel Discussion (Misc queries) 1 February 28th 07 04:11 PM
Can one combo box control the data in a different combo box MarkM Excel Discussion (Misc queries) 5 October 9th 06 11:44 AM
Distinct Vipul Dani Excel Worksheet Functions 4 July 11th 06 07:56 AM


All times are GMT +1. The time now is 06:25 PM.

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

About Us

"It's about Microsoft Excel"