Clearing all items in a collection

  • Thread starter Thread starter Todd Huttenstine
  • Start date Start date
T

Todd Huttenstine

Hey guys

Below is an example of how I created my collection
called "testCollection".

Dim TestCollection As New Collection

I have a code that loops through a range and adds items to
this collection. How do I clear all items in the
collection?


Thanks
Todd
 
Hi Todd
you as a quite regular poster should know not to multipost :-)
 
I didnt multipost. Why do you say I multipost?

-----Original Message-----
Hi Todd
you as a quite regular poster should know not to multipost :-)


--
Regards
Frank Kabel
Frankfurt, Germany

Newsbeitrag news:[email protected]...

.
 
Oh I wondered why my messages were not showing up. I am
at work and when Im at work I have to access the newsgroup
through Microsoft.com. THe default newsgroup it goes to
first is General Questions which is apparently the misc
group you are talking about. I see 2 of the same posts in
there. Sorry I did not intend for them to go to the
misc. I never use that group anyway.


Thanks. I figured out what was going on with my code. I
found out that in order to remove items from a collection,
you must use the .remove method. I was saying .remove
(variable) and it was not working. It kept leaving 1 item
in there. When you remove an item in a collection, the
index resets to 1. I did not know this, so instead I
used .remove 1 and then it worked.


Tod Huttenstine
 
Hi Todd,

Todd said:
Thanks. I figured out what was going on with my code. I
found out that in order to remove items from a collection,
you must use the .remove method. I was saying .remove
(variable) and it was not working. It kept leaving 1 item
in there. When you remove an item in a collection, the
index resets to 1. I did not know this, so instead I
used .remove 1 and then it worked.

Another option is to destroy the collection (Set TestCollection=Nothing).
I've found it to faster, not to mention less code.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 

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