1
Dim arr As New Collection, a
Dim aFirstArray() As Variant    

...some code

For Each a In aFirstArray
   arr.Add a, a
Next

i get this error: This key is already associated with an element of this collection

on this line : arr.Add a, a

what am i doing wrong?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062

1 Answers1

1

Some more code?

from this what you have all I can tell you is that what your error says. The a is already in the collection (the key is supposed to be an unique string). BTW. is the a a string?

Or maybe you have some repetition in your array which would try to add 1+ time the same item?

Mike
  • 2,995
  • 1
  • 18
  • 14
  • mike im using this code: http://stackoverflow.com/questions/3017852/vba-get-unique-values-from-array/3017973#3017973 to get unique values from the array – Alex Gordon Jun 11 '10 at 16:49
  • 1
    You missing out `On Error Resume Next` which omits your error and keeps going, thus your unique values. – Mike Jun 11 '10 at 16:51