Removing a collection item via key name check

  • Thread starter Thread starter Abraham.Olson
  • Start date Start date
A

Abraham.Olson

I have a collection of range objects, called collXcells, and each has a
key cooresponding to the range's R1C1 position (each range is only 1
Excel cell). I.e. if there is a range object that is the A3 cell, its
key for collXcells is "R3C1".

Is there any easy way to check if a key in the collection exists? and
if so remove the item associated with that key? (a way easier--and
preferably more efficient-- than looping through all the collection
objects keys, that is).

Thanks,

-Abe
 
There can't be duplicate keys, so just add the new item and do
On Error Resume Next. If the key was there already the item won't be added.

RBS
 
You might consider using a Dictionary object rather than a
Collection object.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Thanks Chip. I hadn't run into dictionaries before, but I looked into
it and its definitely what I am looking for.

-Abe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top