Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Function Not Recognising Values in Populated Ranges

I have written the following code in order to iterate a discount rate from a
present value and yet it fails to recognise the values in the Target,
Period_Range and Cashflow_Range. It works in another workbook but
unfortunately not the one in which I need it. Can someone please help?

Public Function Iterative_Solution(Target As Double, Guess1 As Double,
Guess2 As Double, Frequency As Double, Period_Range As Range, CashFlow_Range
As Range)

Cycle = 1
Limit = Period_Range.Rows.Count
DiscountFactor1 = 1
DiscountFactor2 = 1
Iteration_Target = Target * 10000
Freq = Frequency

'Initial Valuation at Guess1

For Each New_Period In Period_Range.Cells

DiscountRate1 = Guess1
DiscountRate2 = Guess2

CurrentPeriod = Period_Range.Cells(Cycle).Value

If CurrentPeriod 0.001 Then

DiscountFactor1 = DiscountFactor1 / ((1 + (DiscountRate1 / Freq)) ^
(CurrentPeriod))
DiscountFactor2 = DiscountFactor2 / ((1 + (DiscountRate2 / Freq)) ^
(CurrentPeriod))

Cashflow = CashFlow_Range.Cells(Cycle).Value

DCF1 = Cashflow * DiscountFactor1 + DCF1
DCF2 = Cashflow * DiscountFactor2 + DCF2

Else

End If

Cycle = 1 + Cycle

Next New_Period

Error1 = DCF1 - Iteration_Target
Error2 = DCF2 - Iteration_Target

DiscountRateLast = DiscountRate2
ErrorLast = Error2
DiscountRateThis = DiscountRate2 - ((Error2 * (DiscountRate2 -
DiscountRate1) / (Error2 - Error1)))

'Begin the Iterations runining through five times to hone in on correct answer

For Iteration = 1 To 5

Cycle = 1
DiscountFactor = 1
DCF = 0

For Each New_Period In Period_Range.Cells

CurrentPeriod = Period_Range.Cells(Cycle).Value

If CurrentPeriod 0.001 Then

DiscountFactor = DiscountFactor / ((1 + (DiscountRateThis / Freq)) ^
(CurrentPeriod))

Cashflow = CashFlow_Range.Cells(Cycle).Value

DCF = Cashflow * DiscountFactor + DCF

Else

End If

Cycle = 1 + Cycle

Next New_Period

ErrorThis = DCF - Iteration_Target

If WorksheetFunction.Max(ErrorThis, -ErrorThis) < 0.000001 Then

Exit For

Else

End If

DiscountRateTemp = DiscountRateThis

DiscountRateThis = DiscountRateThis - ((ErrorThis * (DiscountRateThis -
DiscountRateLast) / (ErrorThis - ErrorLast)))

ErrorLast = ErrorThis

DiscountRateLast = DiscountRateTemp

Next Iteration

Iterative_Solution = DiscountRateThis

End Function

Thank you
--
Matt Roberts
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel still not recognising equal values pecan Excel Worksheet Functions 1 July 16th 08 10:40 AM
HELP! - Printing a sheet with values populated from dropdown box Co-op Bank Excel Programming 5 July 13th 05 02:23 PM
Workbook not recognising named ranges Darin Kramer Excel Programming 2 March 17th 05 04:14 PM
Recognising cell values Mikeymay[_2_] Excel Programming 5 August 18th 04 01:11 AM
Copy Values to Below last Populated Cell Q John Excel Programming 2 June 29th 04 05:28 PM


All times are GMT +1. The time now is 11:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"