LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default How to get enique records from data list?

you an use a collection to get the unique values. a scripting dictionary,
part of the scripting runtime is better as it has an Exists method. With the
collection, trying to add a key that already exists raises an error. so by
adding an item to the collection can be used to parse for uniqueness.

1. Using a collection
Sub GetUniqueItems()
Dim cell As Range
Dim coll As Collection

Set coll = New Collection

On Error Resume Next

For Each cell In Range("MyList").Cells

coll.Add cell.Value, cell.Value
If Err.Number = 0 Then
'ok to add
Sheet1.ComboBox1.AddItem cell.Value
Else
' it already exists, hence raises an error
Err.Clear
End If

Next

Set coll = Nothing

End Sub

2. Using a dictionary. set reference to ms.scripting runtime dll
Sub GetUniqueItems()
Dim cell As Range
Dim dic As Scripting.Dictionary

Set dic = New Scripting.Dictionary

For Each cell In Range("MyList").Cells

If Not dic.Exists(cell.Value) Then
dic.Add cell.Value, cell.Value
Sheet1.ComboBox1.AddItem cell.Value
End If

Next

Set dic = Nothing

End Sub


Patrick Molloy
Microsoft Excel MVP

"Ricky S" wrote:

How can I get enique records from a data list in a
worksheet to fill a listbox? I know how to add items to the
list box but isnt there a function to extract the records?

Thanks RS

 
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 to create a macro in excel so that it can generate a list ofunique records using all permutations and combinations of the data in eachrow ad column Rizwan[_4_] Excel Discussion (Misc queries) 1 August 6th 09 01:44 PM
Filtering a list with 67,000 plus records Debra Excel Discussion (Misc queries) 3 February 23rd 09 11:23 PM
Delete records when certain records have duplicate column data JVroom New Users to Excel 1 January 26th 09 06:23 PM
Combo Box for a list of records dascooper Excel Worksheet Functions 2 November 16th 07 09:40 PM
Restructuring records into a list [email protected] Excel Worksheet Functions 2 December 21st 05 09:08 AM


All times are GMT +1. The time now is 09:30 AM.

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"