VBA Code Breakdown Sub Initialize_Static_Array() Visual Basic Copy Sub Initialize_Static_Array(): This line starts the sub procedure called “Initialize_Static_Array”. Dim data(1 To 3, 1 To 3) As String Visual Basic Copy Dim data(1 To 3, 1 To 3) As String: This line declares an ...
We can make a two-dimensional array in VBA readily enough. I’ve modified my earlier routinePlotManyPointsto do just that. My arraysxandyare dimensioned with1 to n rowsand1 to 1columns. Sub PlotManyPoints(n As Long, cht As Chart) Dim x As Variant, y As Variant ' 2-dimensional verti...
Whereas the collection has 3 items, the array only needs to be dimensioned to 2 because there is an element 0 Sub ConvertCollectionToArray() Dim MyCollection As New Collection Dim MyArray(2) As String MyCollection.Add "Item1" MyCollection.Add "Item2" MyCollection.Add "Item3" For n = ...
size of the array you can use ‘ReDim’ to re-size it, but you need to use the keyword ‘Preserve’ if you do not want to lose the data already held in the array. A collection size does not need to be defined. It just grows and shrinks automatically as items are added or ...