LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Problems in copying a Collection to another and removing elementsfrom two Collections

Hi,

two questions on Collections:

1. in VBA, the only way to copy the items (not just the references) of
a collection c1 to another collection c2 is to go through each element
of c1 with a For Each Next and Add each item to c2, right?

2. I have a collection c1 containing some objects to be deleted (the
ones for which the Defective property is True). I want to delete them
from c1 and at the same time to delete the objects in the same
position from another collection c2. See code below:

Sub RemoveDefectivesfromColns(c1 As Collection, c2 As Collection)
Dim obj as Object, I As Long

For I=1 to c1.Count
Set obj =c1(I)
If obj.Defective Then
c1.Remove I
c2.Remove I
End If
Next I
End Sub

Problems: number of elements in c1 and c2 is changing as the cycle
goes on, so sooner or later the Remove method will fail (because I
exceeds the number of remaining elements in c1 and c2). How can I
solve this? Also, is there a way to do this with a For Each In Next?
Would it be faster? Thanks,

Best Regards

deltaquattro











c1.Add Item:="woof"

Set c2=c1

makes
 
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
A List of Collections and Custom Collections ExcelMonkey Excel Programming 1 December 20th 07 10:04 PM
Removing a collection item via key name check [email protected] Excel Programming 3 June 30th 06 03:10 PM
Collection Problems Cody Excel Programming 6 September 1st 05 05:57 PM
Collection Class problems Flemming Dahl Excel Programming 4 February 11th 04 04:41 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 12:24 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"