PC Review


Reply
Thread Tools Rate Thread

Controlling execution of a Sub Procedure

 
 
Don McC
Guest
Posts: n/a
 
      19th Apr 2010
I have a spreadsheet that itself has a recursive (iteration) loop. Once the
sheet converges, I have to look at the results and depending on what they
are, either call a lengthy Sub procedure or bypass it. I cannot use Function
procedures because the lengthy calculation I must perform is itself
iterative. Thus I can't break up the calculation into a number of small
Function procedures. I am now using the worksheet_calculate() event handler,
but evidently the definition of "recalculate the spreadsheet" includes any
cell that is manipulated. Thus what I am running into is the
Worksheet_calculate() sub procedure is being called over and over until the
stack overflows, EVEN though the TEST spreadsheet I am using has only one
cell of data that I change and one calculation. Everything else is static.
Anyone have ANY suggestions around this problem? Any way to call a sub
procedure from the spreadsheet itself? I am using Excel 2003 with all the
patches and updates.

Thanks
 
Reply With Quote
 
 
 
 
Don McC
Guest
Posts: n/a
 
      19th Apr 2010
The problem was in the posting back of results to the same page. Once I
wrote back the results of the Worksheet_calculate() sub procedure to another
page it worked fine. You wouldn't have wanted me to post the code. I
basically had to duplicate one whole spreadsheet within code, so the code was
about 7 standard pages worth....I sure wish excel had a way to control
execution of parts (ranges) of cells better. Worksheet_change and
Worksheet_calculate don't always work very elegantly.

"p45cal" wrote:

>
> There's a few reasons for getting stack overflow, it could be that your
> procedure is changing the worksheet which triggers a sheet
> change/calculation which starts he procedure anew. It could also be that
> your recursive procedure does not have adequate exit strategies.
>
> Is your recursive procedure truly recursive (that is, it calls itself,
> or is it just iterative as in a loop of some sort?
>
> Give us some meat to work on, post some code etc.
>
> ps. There's no reason a vba function can't call itself, recursively,
> iteratively or any other way, whether it passes arguments or not.
>
> I looked up 'recursion' in the dictionary and all I got was: 'see
> Recursion'.
>
>
>

Don McC;703105 Wrote:
> >

> I have a spreadsheet that itself has a recursive (iteration) loop.
> Once the
> > sheet converges, I have to look at the results and depending on what

> they
> > are, either call a lengthy Sub procedure or bypass it. I cannot use

> Function
> > procedures because the lengthy calculation I must perform is itself
> > iterative. Thus I can't break up the calculation into a number of

> small
> > Function procedures. I am now using the worksheet_calculate() event

> handler,
> > but evidently the definition of "recalculate the spreadsheet" includes

> any
> > cell that is manipulated. Thus what I am running into is the
> > Worksheet_calculate() sub procedure is being called over and over until

> the
> > stack overflows, EVEN though the TEST spreadsheet I am using has only

> one
> > cell of data that I change and one calculation. Everything else is

> static.
> > Anyone have ANY suggestions around this problem? Any way to call a

> sub
> > procedure from the spreadsheet itself? I am using Excel 2003 with all

> the
> > patches and updates.
> >
> > Thanks

>
>
> --
> p45cal
>
> *p45cal*
> ------------------------------------------------------------------------
> p45cal's Profile: http://www.thecodecage.com/forumz/member.php?u=558
> View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=196715
>
> http://www.thecodecage.com/forumz
>
> .
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controlling execution of a Sub Procedure -Part 2 :( Don McC Microsoft Excel Programming 0 20th Apr 2010 03:27 PM
why does the execution jump to another procedure? Harold Good Microsoft Excel Programming 4 14th May 2009 02:21 PM
controlling macro execution =?Utf-8?B?c3JlZQ==?= Microsoft Excel Programming 1 21st Feb 2005 01:51 AM
too much for stored procedure execution Keith O Microsoft ADO .NET 3 15th Feb 2005 07:19 PM
Scheduling Procedure execution Sonali Microsoft VB .NET 1 1st Dec 2003 08:22 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:01 AM.