Hi all,
I have made a macro for calculating payback for an investment using a one dimensional array of cash flows. The problem is I would like this to be a function where the user can just select an array and the macro will run automatically using the range that user has provided and output the payback for them.
I am attaching the macro I currently use, where I have to manually set the range. If anyone knows anyway this can be made into a function, please let me know. Thanks!
I have made a macro for calculating payback for an investment using a one dimensional array of cash flows. The problem is I would like this to be a function where the user can just select an array and the macro will run automatically using the range that user has provided and output the payback for them.
I am attaching the macro I currently use, where I have to manually set the range. If anyone knows anyway this can be made into a function, please let me know. Thanks!
Code:
Sub Payback()
On Error Resume Next
Dim R As Range
Set R = Range("I2:I15")
CumCF = 0
i = 0
For Each C In R
If CumCF <= 0 Then
CumCF = CumCF + C.Value
Pybck = i + 1 - (CumCF / R.Cells(i + 1))
End If
i = i + 1
Next
Range("C3") = Pybck
End Sub