Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default VBA to get List of Unique Items from column

As I have painfully learned, a 'Collection' may
prove your solution.

A Collection can only hold unique values. If you
attempt to add a non-unique value, then an error
will be thrown. As J. Walkenbach shows, this
error can be usefully employed.

See http://j-walk.com/ss/excel/tips/tip47.htm
and thanks to Tom Ogilvy.

Perhaps this may help a little. Perhaps not.

Regards.

"Tod" wrote in message
...
Hi,

I have a list of about 2000 records, but only about 12 are
unique. I want to use those unique values to set up a
loop. Currently I'm doing something like this:

i = 0
For Each Cell In ActiveSheet.Range("J2:J1725")
If i = 0 Then
ReDim Preserve ROArray(i)
ROArray(i) = Cell.Value
i = i + 1
Else
For j = 0 To UBound(ROArray)
If Cell.Value = ROArray(j) Then k = k + 1
Next j
If k = 0 Then
ReDim Preserve ROArray(i)
ROArray(i) = Cell.Value
i = i + 1
End If
k = 0
End If
Next Cell

This works fine. I just wonder if I'm missing something
much simpler.

tod



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.520 / Virus Database: 318 - Release Date: 18/09/2003


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default VBA to get List of Unique Items from column

You haven't got that quite right. I think you mean a collection cannot
have items with duplicate keys.

"Stuart" wrote in message ...
As I have painfully learned, a 'Collection' may
prove your solution.

A Collection can only hold unique values. If you
attempt to add a non-unique value, then an error
will be thrown. As J. Walkenbach shows, this
error can be usefully employed.

See http://j-walk.com/ss/excel/tips/tip47.htm
and thanks to Tom Ogilvy.

Perhaps this may help a little. Perhaps not.

Regards.

"Tod" wrote in message
...
Hi,

I have a list of about 2000 records, but only about 12 are
unique. I want to use those unique values to set up a
loop. Currently I'm doing something like this:

i = 0
For Each Cell In ActiveSheet.Range("J2:J1725")
If i = 0 Then
ReDim Preserve ROArray(i)
ROArray(i) = Cell.Value
i = i + 1
Else
For j = 0 To UBound(ROArray)
If Cell.Value = ROArray(j) Then k = k + 1
Next j
If k = 0 Then
ReDim Preserve ROArray(i)
ROArray(i) = Cell.Value
i = i + 1
End If
k = 0
End If
Next Cell

This works fine. I just wonder if I'm missing something
much simpler.

tod



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.520 / Virus Database: 318 - Release Date: 18/09/2003

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
Making list of unique items from two different columns casey Excel Worksheet Functions 10 April 1st 08 07:40 PM
tagging unique items in a list K. Gwynn Excel Worksheet Functions 7 June 16th 06 02:20 PM
Function to count unique items in list XP Excel Worksheet Functions 2 April 10th 06 06:30 PM
How do I set up a formula to count only unique items in a column? jennifer Excel Worksheet Functions 0 March 26th 06 11:55 PM
count unique items in ever-growing list? MeatLightning Excel Discussion (Misc queries) 2 March 17th 06 06:07 PM


All times are GMT +1. The time now is 06: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"