Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Collection of case sensitive unique items

Given red, Red, Blue, blue, blue in A1:A5,

Dim x as New Collection
dim rng as Range
Set rng = Range("A1:A5")
On Error Resume Next
For each iVal in rng
x.Add Item: = iVal, key:= CStr(iVal)
Next

will produce a two-element collection of red and Blue. How can I make
the collection of unique items case sensitive; i.e., a 4-element
collection of red, Red, Blue, blue?

Thanks in advance.

Alan Beban

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Collection of case sensitive unique items

Hello Alan,

You can do it with a Dictionary object...
'--------------------------------
'Requires project reference to the "Microsoft Scripting Runtime"
Sub Test()
Dim x As Scripting.Dictionary
Dim Rng As Range
Dim iVal As Range

Set x = New Scripting.Dictionary
Set Rng = Range("A1:A5")

On Error Resume Next
For Each iVal In Rng
x.Add key:=iVal.Text, Item:=iVal
Next
On Error GoTo 0
Range(Cells(1, 2), Cells(1, x.Count + 1)).Value = x.Keys

Set Rng = Nothing
Set iVal = Nothing
Set x = Nothing
End Sub
'--------------------------------

Regards,
Jim Cone
San Francisco, CA

"Alan Beban" wrote in message ...
Given red, Red, Blue, blue, blue in A1:A5,

Dim x as New Collection
dim rng as Range
Set rng = Range("A1:A5")
On Error Resume Next
For each iVal in rng
x.Add Item: = iVal, key:= CStr(iVal)
Next


will produce a two-element collection of red and Blue. How can I make
the collection of unique items case sensitive; i.e., a 4-element
collection of red, Red, Blue, blue?
Thanks in advance.
Alan Beban


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Collection of case sensitive unique items

Hi Jim,

Thanks. I wouldn't have worked it out on my own.

Alan Beban

Jim Cone wrote:

Hello Alan,

You can do it with a Dictionary object...
'--------------------------------
'Requires project reference to the "Microsoft Scripting Runtime"
Sub Test()
Dim x As Scripting.Dictionary
Dim Rng As Range
Dim iVal As Range

Set x = New Scripting.Dictionary
Set Rng = Range("A1:A5")

On Error Resume Next
For Each iVal In Rng
x.Add key:=iVal.Text, Item:=iVal
Next
On Error GoTo 0
Range(Cells(1, 2), Cells(1, x.Count + 1)).Value = x.Keys

Set Rng = Nothing
Set iVal = Nothing
Set x = Nothing
End Sub
'--------------------------------

Regards,
Jim Cone
San Francisco, CA

"Alan Beban" wrote in message ...

Given red, Red, Blue, blue, blue in A1:A5,

Dim x as New Collection
dim rng as Range
Set rng = Range("A1:A5")
On Error Resume Next
For each iVal in rng
x.Add Item: = iVal, key:= CStr(iVal)
Next




will produce a two-element collection of red and Blue. How can I make
the collection of unique items case sensitive; i.e., a 4-element
collection of red, Red, Blue, blue?
Thanks in advance.
Alan Beban



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Collection of case sensitive unique items

Alan,

You probably would find the Windows Script documentation file of interest - available from...

http://msdn.microsoft.com/library/de...ist/webdev.asp
Microsoft Windows Script 5.6 (Windows 2000, XP)

Regards,
Jim Cone
San Francisco, CA

"Alan Beban" wrote in message ...
Hi Jim,
Thanks. I wouldn't have worked it out on my own.
Alan Beban


Jim Cone wrote:
Hello Alan,
You can do it with a Dictionary object...
'--------------------------------
'Requires project reference to the "Microsoft Scripting Runtime"
Sub Test()
Dim x As Scripting.Dictionary
Dim Rng As Range
Dim iVal As Range
Set x = New Scripting.Dictionary
Set Rng = Range("A1:A5")
On Error Resume Next
For Each iVal In Rng
x.Add key:=iVal.Text, Item:=iVal
Next
On Error GoTo 0
Range(Cells(1, 2), Cells(1, x.Count + 1)).Value = x.Keys
Set Rng = Nothing
Set iVal = Nothing
Set x = Nothing
End Sub
'--------------------------------
Regards,
Jim Cone
San Francisco, CA


"Alan Beban" wrote in message ...


Given red, Red, Blue, blue, blue in A1:A5,
Dim x as New Collection
dim rng as Range
Set rng = Range("A1:A5")
On Error Resume Next
For each iVal in rng
x.Add Item: = iVal, key:= CStr(iVal)
Next
will produce a two-element collection of red and Blue. How can I make
the collection of unique items case sensitive; i.e., a 4-element
collection of red, Red, Blue, blue?
Thanks in advance.
Alan Beban


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Collection of case sensitive unique items

Thanks.

Jim Cone wrote:

Alan,

You probably would find the Windows Script documentation file of interest - available from...

http://msdn.microsoft.com/library/de...ist/webdev.asp
Microsoft Windows Script 5.6 (Windows 2000, XP)

Regards,
Jim Cone
San Francisco, CA

"Alan Beban" wrote in message ...

Hi Jim,
Thanks. I wouldn't have worked it out on my own.
Alan Beban



Jim Cone wrote:

Hello Alan,
You can do it with a Dictionary object...
'--------------------------------
'Requires project reference to the "Microsoft Scripting Runtime"
Sub Test()
Dim x As Scripting.Dictionary
Dim Rng As Range
Dim iVal As Range
Set x = New Scripting.Dictionary
Set Rng = Range("A1:A5")
On Error Resume Next
For Each iVal In Rng
x.Add key:=iVal.Text, Item:=iVal
Next
On Error GoTo 0
Range(Cells(1, 2), Cells(1, x.Count + 1)).Value = x.Keys
Set Rng = Nothing
Set iVal = Nothing
Set x = Nothing
End Sub
'--------------------------------
Regards,
Jim Cone
San Francisco, CA




"Alan Beban" wrote in message ...




Given red, Red, Blue, blue, blue in A1:A5,
Dim x as New Collection
dim rng as Range
Set rng = Range("A1:A5")
On Error Resume Next
For each iVal in rng
x.Add Item: = iVal, key:= CStr(iVal)
Next
will produce a two-element collection of red and Blue. How can I make
the collection of unique items case sensitive; i.e., a 4-element
collection of red, Red, Blue, blue?
Thanks in advance.
Alan Beban



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
countif function: how to distinguish case/make case sensitive mvwoolner Excel Worksheet Functions 3 March 18th 09 02:18 PM
Adding Unique Items to a Collection WJ Excel Discussion (Misc queries) 2 June 12th 07 03:46 PM
Getting a case sensitive match? ob1kenob Excel Worksheet Functions 6 March 28th 06 05:04 AM
Case Sensitive w/ IF jeffP Excel Worksheet Functions 11 February 6th 06 01:16 AM
Case sensitive vlookup Tawe Excel Discussion (Misc queries) 3 June 13th 05 03:43 PM


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