Table of contents
Collapse the table of content
Expand the table of content

Remove Method (Visual Basic for Applications)

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

Removes a member from a Collection object. Syntaxobject.Removeindex The Remove method syntax has the following object qualifier and part:

objectRequired. An object expression that evaluates to an object in the Applies To list.
indexRequired. An expression that specifies the position of a member of thecollection. If a numeric expression, index must be a number from 1 to the value of the collection's Countproperty. If a string expression, index must correspond to the keyargument specified when the member referred to was added to the collection.

Remarks If the value provided as index doesn't match an existing member of the collection, an error occurs.


This example illustrates the use of the Remove method to remove objects from a Collection object, MyClasses. This code removes the object whose index is 1 on each iteration of the loop.

Dim Num, MyClasses
For Num = 1 To MyClasses.Count    
    MyClasses.Remove 1    ' Remove the first object each time
            ' through the loop until there are 
            ' no objects left in the collection.
Next Num
© 2018 Microsoft