mardi 24 février 2015

ReDim existing array with a second dimension?

I declared an array in my VBA function that has a dynamic size. As I cannot ReDim the first dimension of a two- or more-dimensional array, can I add a second dimension to a set array?


This is how I dynamically set the size of my array.



Dim nameArray() As String
Dim arrayCount As Long

For i = 1 To 100
ReDim Preserve nameArray(1 to arrayCount)
nameArray(arrayCount) = "Hello World"
arrayCount = arrayCount + 1
Next i


Now I would like to add a second dimension.



ReDim Preserve nameArray(1 To arrayCount, 1 To 5)


doesn't work.


Is there a workaround?


Aucun commentaire:

Enregistrer un commentaire