Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default creating a 'routine'

Please can someone tell me how easy/difficult this is...

I need to create a routine whe

1. The values of a number of cells in my spreadsheet are built into an
equation.
2. The equation is run repeatedly until the value = 0
3. The information I need is the number of times it is run before value = 0

I have done this 'long hand' but would like it built into the function
contained within one cell. What are the key functions I need to be looking at
in order to create this?

Thank you.

James


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default creating a 'routine'

It would help to know the exact calculation you need to do, but here is what
I have in mind - you could use the function CountIterations in your worksheet
cell:

Public Function CountIterations(Parameter1 as ???, Parameter2 as ???...) as
Integer
Dim CountCalls as Integer, Result as ???
CountCalls = 0, Result = 1
While Not(Result = 0)
Result = MyFunction(Parameter1, Parameter2, ...)
CountCalls = CountCalls + 1
Wend
CountIterations = CountCalls
End Function

Public Function MyFunction(Parameter1 as ???, Parameter2 as ???...) as ???
'Put your function code in here
End Function

A few notes:
1) Since I did not know the proper variable types, I used ???
2) I assume the function may change the values of the cells used for
calculation, since otherwise it would continue to return the same value and
never converge to zero - so your parameters may need to be the actual cells
(Cell1 as Range, Cell2 as Range) passed ByRef so that you can not only use
the values but change their contents.
3) WARNING: If your function returns a Single or Double variable type you
may need to use a different end condition than Result = 0: this is because
rounding inaccuracies may keep the value from ever equalling exactly zero
(this is a common and well known issue with recursive calculations on
computers). You might need your condition to be something like
Abs(Result)<=0.00001 or something like that.

"jamesmcg69" wrote:

Please can someone tell me how easy/difficult this is...

I need to create a routine whe

1. The values of a number of cells in my spreadsheet are built into an
equation.
2. The equation is run repeatedly until the value = 0
3. The information I need is the number of times it is run before value = 0

I have done this 'long hand' but would like it built into the function
contained within one cell. What are the key functions I need to be looking at
in order to create this?

Thank you.

James


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
VBA routine (101) Ray Excel Programming 5 August 26th 05 08:02 PM
creating a routine to help memorize Jim[_22_] Excel Programming 0 July 12th 04 02:34 AM
SUB ROUTINE tokirk Excel Programming 1 January 19th 04 02:17 AM
Routine?? Zax Excel Programming 3 December 19th 03 05:50 PM
Need VBA Routine John M. Lembo Excel Programming 0 July 13th 03 01:51 AM


All times are GMT +1. The time now is 03:29 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"