R
Ron Freudenheim
The purpose of my Access 2002 application is to take
information concerning loans and their underlying
collateral (properties) and to determine what would be the
correct price to pay for the loan, given certain
discounting factors, the underlying cash flow from the
properties, and a desired investment yield.
I have automated the transfer of information from Access
2002 to Excel 2000 and for the most part it works
beautifully!
The key calculation is the Internal Rate of Return and
that is where the problem is.
The code correctly puts the various values that need to be
included in the IRR in the correct places on the
spreadsheet and correctly writes the IRR formula. One of
the data points to be considered in the IRR is the price
that one would pay to purchase the loan.
The code examines the initial resulting IRR, and if it is
less than a pre-set target yield amount, it subtracts
$1000 from the initial price of the loan and again checks
to see if the resulting IRR value is at or above the
target. The code keeps looping and subtracting $1000 with
each pass until the target is met. Once the target is
met, the resulting value is put on a screen form and a
bunch of other things happen.
The problem is that while it appears that the looping is
getting to the correct answer and stoping correctly (by
looking at the output from the Debug.Print lines in the
attached code), the IRR value in the spreadsheet does not
meet the target value. For example, if I am seeking a 10%
IRR, the code will execute through the loops and come up
with a calculated IRR value that is slightly above 10% and
then stop (as it is supposed to), but the value that shows
in the spreadsheet for the IRR is 4.96% and the
corresponding value for the price to pay for the loan is
correctly posted for that IRR(i.e. the IRR function in
Excel is working OK).
Here is what the code looks like:
'Sets the third sheet as the current sheet.
Set ExcelSheet = ExcelBook.Worksheets(3)
'Sets the range to the cell that calculates the IRR
Set rng1 = ExcelSheet.Range("e32")
'Set the cell reference to e19 which is the price to
pay for the loan
intRowNumber = 19
intColumnNumber = 5
'This variable comes from the form that is
loaded "frmCashFlowAssumptions"
varYieldRequirement = Forms!frmCashFlowAssumptions!
YieldRequirement
On Error Resume Next
Do While rng1 < varYieldRequirement
If rng1 < varYieldRequirement Then
'Subtracts 1000 from the value in e19 until
rng1 = > varYieldRequirement
ExcelSheet.Cells(intRowNumber,
intColumnNumber) = ExcelSheet.Cells(intRowNumber,
intColumnNumber) - 1000
Debug.Print "The purchase price is set to " &
ExcelSheet.Cells(intRowNumber, intColumnNumber)
Debug.Print "The IRR is " & rng1
Debug.Print "The cell says " & ExcelSheet.Range
("e32")
Else
End If
Loop
'Puts the derived price to pay (the DIV) which is
in e19 onto the form.
Forms!frmCashFlowAssumptions!DIV = ExcelSheet.Cells
(intRowNumber, intColumnNumber)
The last pass trough the loop produces the following lines
from the Debug.Print:
The purchase price is set to 51668
The IRR is 0.100963374951904
The cell says 0.100963374951904
BUT! the value on the spreadhseet for the IRR is 4.96%
which is the IRR if the loan were purchased for 51668.
The statement "On Error Resume Next" is there in case the
initial IRR value returned on the spreadsheet results in
#NUM! - which leads to a type mismatch error. I am
wondering if because in the initial few passes through the
loop the result is this error, that somehow the calculated
IRR gets out of whack somehow?
Is this possibly a timing problem? What can I do to get
to the correct IRR calculation?
Thanks VERY much in advance.
Ron Freudenheim
(e-mail address removed)
information concerning loans and their underlying
collateral (properties) and to determine what would be the
correct price to pay for the loan, given certain
discounting factors, the underlying cash flow from the
properties, and a desired investment yield.
I have automated the transfer of information from Access
2002 to Excel 2000 and for the most part it works
beautifully!
The key calculation is the Internal Rate of Return and
that is where the problem is.
The code correctly puts the various values that need to be
included in the IRR in the correct places on the
spreadsheet and correctly writes the IRR formula. One of
the data points to be considered in the IRR is the price
that one would pay to purchase the loan.
The code examines the initial resulting IRR, and if it is
less than a pre-set target yield amount, it subtracts
$1000 from the initial price of the loan and again checks
to see if the resulting IRR value is at or above the
target. The code keeps looping and subtracting $1000 with
each pass until the target is met. Once the target is
met, the resulting value is put on a screen form and a
bunch of other things happen.
The problem is that while it appears that the looping is
getting to the correct answer and stoping correctly (by
looking at the output from the Debug.Print lines in the
attached code), the IRR value in the spreadsheet does not
meet the target value. For example, if I am seeking a 10%
IRR, the code will execute through the loops and come up
with a calculated IRR value that is slightly above 10% and
then stop (as it is supposed to), but the value that shows
in the spreadsheet for the IRR is 4.96% and the
corresponding value for the price to pay for the loan is
correctly posted for that IRR(i.e. the IRR function in
Excel is working OK).
Here is what the code looks like:
'Sets the third sheet as the current sheet.
Set ExcelSheet = ExcelBook.Worksheets(3)
'Sets the range to the cell that calculates the IRR
Set rng1 = ExcelSheet.Range("e32")
'Set the cell reference to e19 which is the price to
pay for the loan
intRowNumber = 19
intColumnNumber = 5
'This variable comes from the form that is
loaded "frmCashFlowAssumptions"
varYieldRequirement = Forms!frmCashFlowAssumptions!
YieldRequirement
On Error Resume Next
Do While rng1 < varYieldRequirement
If rng1 < varYieldRequirement Then
'Subtracts 1000 from the value in e19 until
rng1 = > varYieldRequirement
ExcelSheet.Cells(intRowNumber,
intColumnNumber) = ExcelSheet.Cells(intRowNumber,
intColumnNumber) - 1000
Debug.Print "The purchase price is set to " &
ExcelSheet.Cells(intRowNumber, intColumnNumber)
Debug.Print "The IRR is " & rng1
Debug.Print "The cell says " & ExcelSheet.Range
("e32")
Else
End If
Loop
'Puts the derived price to pay (the DIV) which is
in e19 onto the form.
Forms!frmCashFlowAssumptions!DIV = ExcelSheet.Cells
(intRowNumber, intColumnNumber)
The last pass trough the loop produces the following lines
from the Debug.Print:
The purchase price is set to 51668
The IRR is 0.100963374951904
The cell says 0.100963374951904
BUT! the value on the spreadhseet for the IRR is 4.96%
which is the IRR if the loan were purchased for 51668.
The statement "On Error Resume Next" is there in case the
initial IRR value returned on the spreadsheet results in
#NUM! - which leads to a type mismatch error. I am
wondering if because in the initial few passes through the
loop the result is this error, that somehow the calculated
IRR gets out of whack somehow?
Is this possibly a timing problem? What can I do to get
to the correct IRR calculation?
Thanks VERY much in advance.
Ron Freudenheim
(e-mail address removed)