I've written the following simple VBA function to calculate linear progression between two amounts for some amount of intervals and return the progression as an array:
Public Function applyLinear(startAmount As Double, stopAmount As Double, Intervals As Integer)
Dim diff As Double
Dim resultArr() As Double
Dim counter As Integer
diff = stopAmount - startAmount
ReDim resultArr(Intervals, 0)
resultArr(0, 0) = startAmount
For counter = 1 To (Intervals)
resultArr(counter, 0) = resultArr(counter - 1, 0) + diff / Intervals
Next ' counter
counter = 0
applyLinear = resultArr
End Function
Unfortunately, what actually gets outputted to the worksheet depends entirely on how many cells the above formula is called from. (This means that it becomes laughably easy for a user to apply the function incorrectly!)
How can I ensure that the entire array is outputted to the worksheet under all circumstances?
Edit: Or rather, more specifically, how can I get VBA to output the entire array when calling the above UDF from a single cell?
Edit 2: Some more clarification. The function does work as intended if "intervals+1" rows are used when calling it. A problem arises however, if (for example) the user accidentally calls the function from 4 rows when intervals is > 4. In this case only the first four elements of resultArr are outputted to the worksheet, this is an issue because it doesn't represent the full linear progression.