Adding


Collection.Add (item [,key] [,before] [,after])

Adds a member to a Collection object.
Whether the before or after argument is a string expression or numeric expression, it must refer to an existing member of the collection, or an error occurs.
An error also occurs if a specified key duplicates the key for an existing member of the collection.


Item
The expression of any type to add to the collection
Required. An object expression that evaluates to an object in the Applies To list.


Key
A unique string that can be used to access an item in the collection instead of using the positional index
Required. An expression of any type that specifies the member to add to the collection.


Before
The relative position identifying the member before the new item has been added.
This value must be between 1 and the total number of items in the collection
Optional. An expression that specifies a relative position in the collection. The member to be added is placed in the collection before the member identified by the before argument. If a numeric expression, before must be a number from 1 to the value of the collection's Count property. If a string expression, before must correspond to the key specified when the member being referred to was added to the collection. You can specify a before position or an after position, but not both.


After
The relative position identifying the member after the new item has been added
Optional. An expression that specifies a relative position in the collection. The member to be added is placed in the collection after the member identified by the after argument. If numeric, after must be a number from 1 to the value of the collection's Count property. If a string, after must correspond to the key specified when the member referred to was added to the collection. You can specify a before position or an after position, but not both.


You can add objects to a collection at a specific point by specifying either the before or after parameters of the add method


How not to add Items

For lrowno = 1 to 10 
   On Error Resume Next
   colMyCollection.Add Cells(lrowno,1).value, Cells(lrowno,2).Value
   On Error GoTo 0
Next lrowno

What happens you just add an item to a collection with no key specified
(key is optional)



© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext