LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Iterative solving using VBA ...

All,
This is more of a general programming question, but I am posting to this
group to see if I can get help with the answer.

I have a public function that sums the future values (fv) of investments,
using a given rate of return (r). For example, the syntax is "fv(r)", where
"fv(0.03)" would return the future values at an annual growth rate of 3%.

Now, suppose the value returned is 30,000 but the actual value I was
expecting was 50,000 (val). I need a procedure to: 1) increment r, 2) pass
it to fv, and 3) iterate through 1 and 2 until the fv function returns a
value "close to" val.

What I have so far (see below) works well, but is ugly. Is there a more
elegant way to do this iteration?

Thanks,
Chris

VBA:
'Start by guessing at 3%
s = 0.03

If fv(s) < val Then
Do
'increment by whole percents
s = s + 0.01
Loop Until fv(s) val

'oops ... too far ... back out a percent
s = s - 0.01

Do
'increment by a tenth percent
s = s + 0.001
Loop Until fv(s) val

'oops ... too far ... back out a tenth percent
s = s - 0.001

Do
'increment by a hundredth percent
s = s + 0.0001
Loop Until fv(s) val

'oops ... too far ... back out a hundredth percent
s = s - 0.0001

Else
' Code here if guess is too high
End If


 
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
Iterative Equation Chris Excel Discussion (Misc queries) 5 March 9th 10 01:32 AM
an iterative calculation -- sort of ali Excel Worksheet Functions 4 July 30th 09 07:57 PM
Excel Iterative calculations petersampson Excel Worksheet Functions 3 December 31st 08 07:30 AM
Iterative process, bioyyy Excel Discussion (Misc queries) 5 December 1st 05 02:07 AM
Iterative Macro Stuart Steven Excel Programming 7 July 14th 04 02:49 PM


All times are GMT +1. The time now is 08:10 PM.

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

About Us

"It's about Microsoft Excel"