long time listener, first time caller
I need to create arrays where the dimensions of each array and the number of arrays is determined by user input. This means that each time the code is executed, there will be a varying amount of arrays created and each array could have varying dimensions. Is there a way to create a for loop that will create these new arrays for me in VBA?
For example, lets say the user indicates the need to create 3 arrays. They then indicate Array 1 should be 5 x 6, array 2 should be 6 x 6, and array 3 should be 6 x 3. I am trying to find a way to create a for loop that will perform the following without me needing to actually create each array:
Dim W1() As Double
ReDim W1(5,6)
Dim W2() As Double
ReDim W1(6,6)
Dim W3() As Double
ReDim W1(6,3)
Something like the code below is what i had in mind.
'UserInput1 is the number of arrays needed
'xDim(i) and yDim(i) are two arrays whose length is equal to UserInput1
'each value in the xDim and yDim arrays represents the X or Y dimension of the
'new array to be created
'i want to create new arrays W1, W2, ...Wn, but using the code W & i() does
'not work
For i = 1 to UserInput1
Dim W & i() As Double
ReDim W & i(xDim(i), yDim(i))
Next i
The code above of course results in an error
"Compile error: expected: end of statement"
Is there a solution to my problem in VBA or is there some other work around I'm not thinking of?
Any help is greatly appreciated! This is my first question asked so please let me know if I need to share any other information.