Thread: VBA Collections
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default VBA Collections

The idea of assigning a Key is so that you can use it in place of knowing or
having to track the position number of your item within the collection
(especially since the position number can change with deletions of items
ahead of the item), so the assumption is that you *know* which Key you are
using to track any particular item. To the best of my knowledge, there is no
way to retrieve the Key assigned to an item in code... and, quite frankly, I
can't think of a scenario where being able to do so would be needed. Can you
explain why you think you would need to do what you have asked (perhaps we
can suggest an alternative to you)?

--
Rick (MVP - Excel)


"JP Ronse" wrote in message
...
Hi All,

Is there a method to get the used key back from a collection?

Suppose you have some (very stupid code) like this:

set c = new collection

c.add item:=1, key:="A"
c.add item:=2, key:="B"
c.add item:=3, key:="C"

How to know which key was used for c(1), c(2)...

TIA.

Wkr,

JP