I am using an excel sheet to track all my investments. In order to calculate my IRR, I need to have the values entered in a specific way for Excel to calculate. So I decided to create a custom function. I will feed this custom function the following values.
- Total Investment
- Time Period of investment
- Final Value of the investment.
I used the following code for creating a custom function. But I get the #VALUE
error
Function ROI(fundInvested, timePeriod, finalValue)
eachValue = fundInvested / timePeriod
Dim cashFlow() As Double
Dim n As Integer
For n = 0 To (timePeriod - 1)
cashFlow(n) = -1 * eachValue
Next n
cashFlow(timePeriod) = finalValue
ROI = IRR(cashFlow)
End Function
Where is my formula wrong?