This documentation is archived and is not being maintained.

Remove Method

Removes a member from a Collection object.

Public Overloads Sub Remove(ByVal { Key As String | Index As Integer })


A unique String expression that specifies a key string that can be used, instead of a positional index, to access a member of the collection.
An expression that specifies the position of a member of the collection. If a numeric expression, Index must be a number from 1 to the value of the collection's Count property. If a String expression, Index must correspond to the Key argument specified when the member referred to was added to the collection.


Exception type Error number Condition
ArgumentException 5 Key is invalid or not specified.
IndexOutOfRangeException 9 Index does not match an existing member of the collection.


If 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, birthdays.

Dim birthdays As New Collection()
birthdays.Add(New DateTime(2001, 1, 12), "Bill")
birthdays.Add(New DateTime(2001, 1, 13), "Joe")


Namespace: Microsoft.VisualBasic

Module: Collection

Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)

See Also

Add Method | ArgumentException Class | IndexOutOfRangeException Class

Applies to

Collection Object