I have no idea what you're trying to say with your description of "Collection".
Lots of things in Excel have Collections.
workbooks
worksheets
shapes
 
but I don't think that really has anything to do with your question.
 
I use the Dictionary object a LOT.
 
In your example, you've created a Dictionary object xDic.
 
Set xDic = CreateObject("Scripting.Dictionary")

Then you test to see if the xChar object exists in your dictionary:
If xDic.Exists(xChar) Then
Else

If it DOESN'T exist, then add it using:

xDic.Add xChar, (some value)

If you attempt to add a duplicate xChar to the dictionary, you will get an 
error.

Once your Dictionary exists, the "unique" values are called the "keys".

using:

sArray = xDic.keys

you will create an array of the key values of xDic.

to loop through all of the values of xDic, use:

for I = 0 to ubound(sArray)

if you've stored some value in the xDic with the xChar key (I didn't see one)

you could get it using:

xDic.item(sArray(I))

-------------
I'm not sure what you were intending with:
xDic(xChar) = ""
xOutValue = xOutValue & xChar

The program logic looks like you're looping through all of the characters in 
the value of pWorkRng.

It LOOKS like you were trying to build a variable called xOutValue
that contains only unique values.

But you're never ADDING a value to the dictionary.
(and you cannot CLEAR value from the dictionary).

This would give you a list of all characters in the Range that only appear once:
Function RemoveDupes1(pWorkRng As Range) As String
    Dim xValue As String
    Dim xChar As String
    Dim xOutValue As String
    Dim xDic
    Dim I As Integer
    Dim sArray
    
    Set xDic = CreateObject("Scripting.Dictionary")
    
    xValue = pWorkRng.Value
    
    For I = 1 To Len(xValue)
        xChar = Mid(xValue, I, 1)
        'This will collect the COUNT of each character in the string
        If (xDic.Exists(xChar)) Then
            xDic.Item(xChar) = xDic.Item(xChar) + 1
        Else
            xDic.Add xChar, 1
        End If
    Next I
    xOutValue = ""
    sArray = xDic.keys
    For I = 0 To UBound(sArray)
        If (xDic.Item(sArray(I)) = 1) Then
            xOutValue = xOutValue & sArray(I)
        End If
    Next I
    RemoveDupes1 = xOutValue
End Function



Paul
-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
-----------------------------------------

 From: Mandeep Baluja <rockerna...@gmail.com>
>To: excel-macros@googlegroups.com 
>Sent: Thursday, December 4, 2014 6:20 AM
>Subject: $$Excel-Macros$$ Scripting.dictionary
>  
>
>
>While studying I got to know that Collection is the object that can take only 
>unique values with the key identifier and i am taking this advantage of this. 
>Another one which is having this special property  is Scripting.dictionary 
>object. Can someone incorporate the usage of scripting.dictionary object with 
>a small example which is showing that it can't take duplicates. 
>
>
>See dis example . 
>Show me how to retireve the value one by one from dictionary object with loop 
>which is stored in dictionary object. (what keyword will be used to get the 
>values one by one item/array(0) something like that.  I dont know the exact 
>
>
>Function RemoveDupes1(pWorkRng As Range) As String
>Dim xValue As String
>
>Dim xChar As String
>Dim xOutValue As String
>
>
>Set xDic = CreateObject("Scripting.Dictionary")
>xValue = pWorkRng.Value
>For i = 1 To VBA.Len(xValue)
>xChar = VBA.Mid(xValue, i, 1)
>If xDic.Exists(xChar) Then
>Else
>xDic(xChar) = ""
>xOutValue = xOutValue & xChar
>End If
>Next
>RemoveDupes1 = xOutValue
>End Function
>
>
>
>
>
>
>Mandeep 
>Learningzmypassion
>https://www.linkedin.com/profile/view?id=312532939
>https://www.facebook.com/VBAEXCELSQL?ref=hl
-- 
>Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
>=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
>https://www.facebook.com/discussexcel
> 
>FORUM RULES
> 
>1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
>Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
>quick attention or may not be answered.
>2) Don't post a question in the thread of another member.
>3) Don't post questions regarding breaking or bypassing any security measure.
>4) Acknowledge the responses you receive, good or bad.
>5) Jobs posting is not allowed.
>6) Sharing copyrighted material and their links is not allowed.
> 
>NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
>members are not responsible for any loss.
>--- 
>You received this message because you are subscribed to the Google Groups "MS 
>EXCEL AND VBA MACROS" group.
>To unsubscribe from this group and stop receiving emails from it, send an 
>email to excel-macros+unsubscr...@googlegroups.com.
>To post to this group, send email to excel-macros@googlegroups.com.
>Visit this group at http://groups.google.com/group/excel-macros.
>For more options, visit https://groups.google.com/d/optout.
>
>
>    

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.

Reply via email to