title: Using a For Loop to Create New Arrays in VBA
body: <p><strong>long time listener, first time caller</strong><br>
  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?</p>
  
  <p>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:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Dim W1() As Double 
      ReDim W1(5,6)
  Dim W2() As Double 
      ReDim W1(6,6)
  Dim W3() As Double 
      ReDim W1(6,3)
  </code></pre>
  
  <p>Something like the code below is what i had in mind. </p>
  
  <pre class="lang-vb prettyprint-override"><code>
  '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 &amp; i() does
  'not work
  
  For i = 1 to UserInput1
      Dim W &amp; i() As Double
          ReDim W &amp; i(xDim(i), yDim(i))
  Next i
  
  </code></pre>
  
  <p>The code above of course results in an error </p>
  
  <blockquote>
    <p>"Compile error: expected: end of statement"</p>
  </blockquote>
  
  <p>Is there a solution to my problem in VBA or is there some other work around I'm not thinking of?</p>
  
  <p>Any help is greatly appreciated! This is my first question asked so please let me know if I need to share any other information.</p>