title: VBA: Summing a matrix
body: <p>Why doesn't this function work?</p>
  
  <p>Type <code>=funtest(2.1)</code> in Excel and it'll give me <code>#VALUE!</code>. </p>
  
  <pre><code>Public Function funtest(a As Double) As Double
  
  Dim z, j, i As Integer
  Dim matrix(3, 3, 3) As Double
  
  For z = 0 To 3 Step 1
  For j = 0 To 3 Step 1
  For i = 0 To 3 Step 1
  
  matrix(z, j, i) = a
  
  Next i, j, z
  
  funtest = Application.WorksheetFunction.Sum(matrix)
  
  End Function
  </code></pre>