Is there an easy way to populate a Collection with all Values from an Array in VBA?
e.g. something like
Dim c As New Collection
Dim a(10) As Variant
...
c.AddAll a
A simple solution would be of cause to iterate over the array, but I would expect that a modern language offers such methods out of the box …
Dim c As New Collection
Dim a(10) as Variant
...
For Each item in a
c.Add item
Next item
Thanks for any hints!
“modern language” is where your problem lies – VBA/VB6 aren’t really modern – neither have been advanced much for some years.
If you need to do it a lot, write a function to do the looping:
or if you want a new collection each time:
and then use it:
or