J
James
In an attempt to calculate a "simple" Internal Rate of Return based off a few
textboxes on a form, I can get the =IRR() function to work properly if and
only if each value in the array is sizably different. If they aren't
different, Access errors out with the message, "Run-time error '5'; Invalid
procedure call or argument" and highlights the last line of the code. I've
been able to replicate this error time and time again if the values 1 through
3 are the same, but if they are different, like I mentioned, it runs fine.
Here is the code:
----------------------------
Dim Fmt, RetRate, Msg, Count, IRRInital, IRRCashFlow, IRRCashFlowFinal
Static Values(4800) As Double ' Set up array.
IRRInitial = -19044.51
IRRCashFlow = 572.64
IRRCashFlowFinal = 100
'Guess = 0.1 ' Guess starts at 10 percent.
Fmt = "#0.00" ' Define percentage format.
'Initial value will always be negative
Values(0) = IRRInitial
' Positive cash flows reflecting income for four successive years.
Values(1) = IRRCashFlow
Values(2) = IRRCashFlow + 5000 'Extra normally not added
Values(3) = IRRCashFlow + 18000 'Extra normally not added
Values(4) = IRRCashFlowFinal
' Calculate internal rate--guess amount not required or needed.
Me.txtGENIRR = IRR(Values()) * 12
----------------------------
Two things should be noted; first, in the real world you will have the
initial number be negative, always, followed by a string of generally equal
and predictable cashflows (loan payments for example). The final cashflow
(or loan payment) may or may not be equal to the previous amounts. Second,
in Excel using the built in IRR function, you'd select a range of cells with
the same amounts as above (-19044.51, 572.64, 572.64, 572.64, 100.00) and it
works just fine.
In addition, I would not have specific amounts placed in the code.
Normally, they would be tied back to textboxes on the form to pull from, then
calculate, and output to a textbox on the same form. I put them here for an
example
As some added assistance, you can find more information about the IRR
function from this Access 2007 page on Microsoft's site--the place where I
obtained part of my
code...http://office.microsoft.com/en-us/access/HA012288611033.aspx.
If anyone can see what I'm doing wrong here if it is with the declaration of
the array or tell if it is a bug I'd greatly appreciate it!
Thanks!!
textboxes on a form, I can get the =IRR() function to work properly if and
only if each value in the array is sizably different. If they aren't
different, Access errors out with the message, "Run-time error '5'; Invalid
procedure call or argument" and highlights the last line of the code. I've
been able to replicate this error time and time again if the values 1 through
3 are the same, but if they are different, like I mentioned, it runs fine.
Here is the code:
----------------------------
Dim Fmt, RetRate, Msg, Count, IRRInital, IRRCashFlow, IRRCashFlowFinal
Static Values(4800) As Double ' Set up array.
IRRInitial = -19044.51
IRRCashFlow = 572.64
IRRCashFlowFinal = 100
'Guess = 0.1 ' Guess starts at 10 percent.
Fmt = "#0.00" ' Define percentage format.
'Initial value will always be negative
Values(0) = IRRInitial
' Positive cash flows reflecting income for four successive years.
Values(1) = IRRCashFlow
Values(2) = IRRCashFlow + 5000 'Extra normally not added
Values(3) = IRRCashFlow + 18000 'Extra normally not added
Values(4) = IRRCashFlowFinal
' Calculate internal rate--guess amount not required or needed.
Me.txtGENIRR = IRR(Values()) * 12
----------------------------
Two things should be noted; first, in the real world you will have the
initial number be negative, always, followed by a string of generally equal
and predictable cashflows (loan payments for example). The final cashflow
(or loan payment) may or may not be equal to the previous amounts. Second,
in Excel using the built in IRR function, you'd select a range of cells with
the same amounts as above (-19044.51, 572.64, 572.64, 572.64, 100.00) and it
works just fine.
In addition, I would not have specific amounts placed in the code.
Normally, they would be tied back to textboxes on the form to pull from, then
calculate, and output to a textbox on the same form. I put them here for an
example
As some added assistance, you can find more information about the IRR
function from this Access 2007 page on Microsoft's site--the place where I
obtained part of my
code...http://office.microsoft.com/en-us/access/HA012288611033.aspx.
If anyone can see what I'm doing wrong here if it is with the declaration of
the array or tell if it is a bug I'd greatly appreciate it!
Thanks!!