Access/VBA Library

ArrayToCollection

Converts (a part of) an Array or to a Collection.

Syntax

ArrayToCollection( vArray [, StartIndex] [, EndIndex] )
Parameters
Name Type Description
vArray Variant Required. The array to be converted.
StartIndex Long Optional. The first index of the array to be converterd. If omitted the LBound of the array will be the first index.
Default: -1
EndIndex Long Optional. The last index of the array to be converterd. If omitted the UBound of the array will be the last index.
Default: -1
Return value

Collection

Code
Function ArrayToCollection(vArray, _
                           Optional ByVal StartIndex As Long = -1, _
                           Optional ByVal EndIndex As Long = -1) As Collection
    Dim idx As Long
    Dim result As New Collection
    
    If StartIndex = -1 Then StartIndex = LBound(vArray)
    If EndIndex = -1 Then EndIndex = UBound(vArray)
    
    For idx = StartIndex To EndIndex
        result.Add vArray(idx)
    Next idx
    
    Set ArrayToCollection = result
End Function

Arraytag:ArrayCollectiontag:Collection