title: Return dynamic array from function VBA
body: <p>I am trying to create a function that outputs an array.
  However, I got the Function call on left-hand side must return Variant or
  Object.  How can I return a dynamic array from this function?</p>
  
  <pre><code>Public Function Fibonacci_Array(max As Integer) As Integer
  
  
      Dim result()   As Variant
      ReDim result(0 To max)
  
      '' Array indices.
      Dim i1         As Integer
      Dim i2         As Integer
      Dim i          As Integer
  
      i1 = 0
      i2 = 1
  
  
      '' Array values.
      Dim newVal     As Long
      Dim prev2      As Long
      Dim prev       As Long
  
      prev2 = 0
      prev = 1
  
      '' Loop through
      While prev &lt;= max
  
              result(i1) = prev2
              result(i2) = prev
  
  
              newVal = prev + prev2
              ''Debug.Print newVal
  
              prev2 = prev
              prev = newVal
  
              i1 = i1 + 1
              i2 = i2 + 1
      Wend
  
      '' Problem here.
      Fibonacci_Array() = result
  
  End Function
  </code></pre>