Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Removing a collection item via key name check

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Removing a collection item via key name check

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

wrote in message
ups.com...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Removing a collection item via key name check

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


wrote in message
ups.com...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Removing a collection item via key name check

Thanks Chip. I hadn't run into dictionaries before, but I looked into
it and its definitely what I am looking for.

-Abe

Chip Pearson wrote:
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


wrote in message
ups.com...
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


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
Pivot Item: removing non-existant item from the drop down CinqueTerra Excel Programming 2 February 23rd 06 08:47 PM
Cannot remove item from collection Kou Vang[_2_] Excel Programming 1 January 31st 06 08:24 PM
Check for an item in a collection (without looping) Rob Excel Programming 2 February 10th 05 11:18 AM
Retrieving a Collection Item Todd Huttenstine Excel Programming 2 October 27th 04 07:15 PM
Removing an Item From a Collection Dan Gesshel Excel Programming 4 November 1st 03 01:12 PM


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