Last active
January 21, 2016 20:10
-
-
Save maximpertsov/6995b6b3a23e50424172 to your computer and use it in GitHub Desktop.
Convert a VBA collection to an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function CollectionToArray(C As Collection, Optional StartIdx As Long, Optional Size As Long) As Variant | |
' Convert a collection into an array | |
Dim A() As Variant | |
Dim Ci As Variant ' Collection element | |
Dim i As Long | |
' Make sure Size is not less than collection size | |
If Size < C.Count Then Size = C.Count | |
' Set starting index (zero by default) | |
i = StartIdx | |
' Transfer collection to array | |
ReDim A(i To i + Size - 1) | |
For Each Ci In C | |
A(i) = Ci | |
i = i + 1 | |
Next | |
CollectionToArray = A | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment