I can't remember a fast way to clear/empty a Collection object. I have a Collection called myItems with thousands of items in it that I want to clear so I can reuse it, but I don't want to iterate through it. . .
Collections unfortunately do not have RemoveAll - unlike a Dictionary object. This is a flaw IMHO. I don't think you can do it except by iterating Remove. Bummer. I am going to flag this one, just in case someone DOES know....but if you are asking, I'm kidda doubting.
Well, the good news is that to loop through a collection of 64,000 objects to clear it takes less than half a second. That definitely suprised me! The code I used is:
-------------------------------------------------------------------------------------------- We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
Does that not simply set the instance of collection object to nothing? Does it really empty the collection of items? Learn something every day. Doh, indeed.
I'm not quite 100% sure but my understanding is that if there are no references to an object, it is destroyed. I just ran a few tests and execution of setting a collection object to nothing took about 30 seconds for a collection of 3million+ elements suggesting it does something more than just zeroising the pointer.
Enjoy,
Tony
-------------------------------------------------------------------------------------------- We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
Didn't know you could put 3 million items in a collection! Which brings up a related question - how many objects CAN you put in a collection? Is it limited only by system resources, or is there a built-in "cap" in Excel?
-------------------------------------------------------------------------------------------- We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.