title: Filter Array in Excel VBA
body: <p>How can I filter a multidimensional array?</p>
  
  <p>My code does neither work nor does it seem neat:</p>
  
  <pre><code>Option Explicit
  Sub CalcE()
  Dim TotalRows As Long
  Dim myArray, myArray2 As Variant
  Dim i, a As Integer
  </code></pre>
  
  <p>Populate Array</p>
  
  <pre><code>TotalRows = Sheets("Data").Rows(Rows.Count).End(xlUp).Row
  myArray = Sheets("Data").Range("A5:F" &amp; TotalRows)
  MsgBox "Array populated with " &amp; UBound(myArray) &amp; "entries."
  </code></pre>
  
  <p>Filter myArray entries into myArray2, but only the column 1, 4 and 6.</p>
  
  <pre><code>a = 0
  For i = 0 To UBound(myArray)
      If myArray(i, 1) &gt; 1 Then
          myArray2(a, 1) = myArray(i, 1)
          myArray2(a, 2) = myArray(i, 4)
          myArray2(a, 3) = myArray(i, 6)
          a = a + 1
      End If
  Next i    
  MsgBox "Array populated now with " &amp; UBound(myArray2) &amp; "entries."
  End Sub
  </code></pre>
  
  <p>I googled and figured that arrays in Excel seem to be very inflexible things, not nice to work with. People usually give up on VBA Arrays and use AutoFilter methods instead. I wounder whether there really isn't a good way. It would be so neat to have!</p>