+ Reply to Thread
Results 1 to 18 of 18

Runtime error 28 Call Stack

  1. #1
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Runtime error 28 Call Stack

    Sub (NEXT) calls the sub (ETC), which calls sub (NEXT)

    The subs just loop through a range of cells flagging errors.

    All fine & dandy but occasionally I get a runtime 28 error, usually happens around the 100th loop.

    I believe it is because of the recursive calling of subs. Any ideas on how to fix it?

    Thanks in advance for your assistance.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Runtime error 28 Call Stack

    without seeing any code, no ;-)
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Runtime error 28 Call Stack

    Please Login or Register  to view this content.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Runtime error 28 Call Stack

    remove the call to NEXT from ETC, or change do stuff to do other stuff

    or if you'd like some actual help, post some actual code

  5. #5
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Runtime error 28 Call Stack

    As I said above, the code runs properly for at least 100 iterations, then it throws a runtime 28 error.

    i.e. the problem is not with the do stuff code.

    The problem is with the recursive calling, as I understand it.
    How do you clear the "Call stack", if that is possible?

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Runtime error 28 Call Stack

    the only way to clear the call stack is to end your code. the rest of the code might have given some clue why you think you need to set up an infinite loop which will always lead to a stack space problem. you say it only happens occasionally which means that something must be exiting the loop but you have not shown us what

  7. #7
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Runtime error 28 Call Stack

    It is not an infinite loop.

    There is a list of values in worksheet 1, usually 120
    The sub Next gets the value of a cell in worksheet1 and finds the record related to that cell in worksheet 2.

    The sub ETC checks the record from worksheet2 for errors (if it finds an error then it simply adds 1 to a counter x) , if no errors are found (x=0) it goes to the next value from the list in worksheet 1 and does exactly the same thing.


    Even when I combine Next and ETC into a single sub I get the same runtime28 error, again , after the code runs through about 100 values.


    EDIT: if it does find an error it exits the loop.

    Please Login or Register  to view this content.
    Last edited by anrichards22; 09-17-2017 at 01:50 AM.

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Runtime error 28 Call Stack

    what little code you have posted is an infinite loop. since you don't seem to want to post the actual code I can't help you. good luck

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Runtime error 28 Call Stack

    As Joseph has said. Share your code with us by attaching the workbook and noting exactly how you start the macro running and which sheet is active when you start it.

    Otherwise it's impossible to comment.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  10. #10
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,616

    Re: Runtime error 28 Call Stack

    May be you shall not call next in etc at all?
    As ypu presented in post #3 the control is returned to next anyway after etc is finished.

    So may be such approach would do the job:

    Please Login or Register  to view this content.

    Please note that our https://www.excelforum.com/forum-rul...rum-rules.html require that even such code like:
    Please Login or Register  to view this content.
    shall be presented in code tags
    So please edit your post #7 accordingly
    Last edited by Kaper; 09-15-2017 at 09:44 AM.
    Best Regards,

    Kaper

  11. #11
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Runtime error 28 Call Stack

    Perhaps this will help: https://msdn.microsoft.com/en-us/lib...(v=vs.60).aspx The first bullet point makes specific mention of "recursive procedures" like you have here. They mention pulling up the Calls or the Call Stack dialog in debug mode to see how many procedure calls are on the stack. A thread over at stackoverflow suggested anywhere from 1000 to 5000 calls (seems machine/OS environment dependent) before getting the stack overflow error.

    It seems to me that you may need to spend some time with your loop and see if you have it structured for efficient recursion. I don't see how we can help you with that process without seeing your code.

    Perhaps these will give some considerations: https://docs.microsoft.com/en-us/dot...ive-procedures
    http://www.cpearson.com/excel/recursiveprogramming.aspx
    http://www.tushar-mehta.com/publish_..._recursion.htm
    https://en.wikipedia.org/wiki/Recurs...puter_science)
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  12. #12
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Runtime error 28 Call Stack

    Quote Originally Posted by JosephP View Post
    what little code you have posted is an infinite loop. since you don't seem to want to post the actual code I can't help you. good luck
    As I explained above, it is NOT an infinite loop.

    The sub NEXT iterates through a range of values in a worksheet.

    The sub ETC simply checks for errors and if none are found it calls NEXT which gets the record for the next value.

    There is a FINITE number of values that NEXT can iterate through.

  13. #13
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Runtime error 28 Call Stack

    Quote Originally Posted by Kaper View Post
    May be you shall not call next in etc at all?
    As ypu presented in post #3 the control is returned to next anyway after etc is finished.

    So may be such approach would do the job:

    Please Login or Register  to view this content.

    Please note that our https://www.excelforum.com/forum-rul...rum-rules.html require that even such code like:
    Please Login or Register  to view this content.
    shall be presented in code tags
    So please edit your post #7 accordingly

    The issue that I have is that the ETC code is the one that flags for errors.

    On further research I believe the problem I have is that ETC does not end.

    Next calls ETC which calls NEXT which calls ETC and eventually the stack is full.

    If I put the NEXT and ETC code in the same sub it still ends up calling itself and eventually runs out of stack space...

    I took your advice and rewrote the loop, as a normal loop in a single sub and it works fine.

  14. #14
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Runtime error 28 Call Stack

    Whilst I have solved my problem, it would be useful to learn more about this stack space problem for future reference.

    Is it bad coding to have recursive calling?

  15. #15
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Runtime error 28 Call Stack

    Quote Originally Posted by anrichards22 View Post
    As I explained above, it is NOT an infinite loop.
    your actual code may not be an infinite loop (although the stack space error suggests otherwise and you essentially admit as much in post #13) but the code you posted certainly is. there are no exits or conditions in anything that you have actually provided

  16. #16
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Runtime error 28 Call Stack

    Quote Originally Posted by JosephP View Post
    your actual code may not be an infinite loop (although the stack space error suggests otherwise and you essentially admit as much in post #13) but the code you posted certainly is. there are no exits or conditions in anything that you have actually provided

    As I explained 3 times to you...The NEXT code loops through a range of values. Part of the 'do stuff' code exits the NEXT sub when it reaches the last value.

    The runtime 28 error is a result of the recursive calling in my code, yes it effectively creates an infinite loop but as I have explained 3 times to you, has nothing to do with the 'do stuff' part of the code. You have so far completely ignored my query, or refused to provide any meaningful advice, instead insisting on seeing code which has no relevance to the problem.

    The line of code in the ETC sub that calls NEXT is creating the runtime error because it is highlighted when the code bugs out.

  17. #17
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Runtime error 28 Call Stack

    I took Kaper's advise and rewrote my loop to overcome the recursive calling error.
    The solution turned out to be relatively simple, so thank you Kaper!


    Please Login or Register  to view this content.

    Instead of having x as a variable in ETC, everytime the ETC codes finds an error it adds 1 to Range("A6") , then I simply test the value in Range("A6") to let the code continue. Problem solved.




    Just to be clear. I was not being ungrateful for the help offered.
    I tested the code myself, as I presented it earlier in the thread, with the all of the 'do stuff' commented out, so I was 100% certain that the 'do stuff' code was NOT the cause of the error.
    As was pointed out, it was an infinite loop, my query related to how best to overcome this.
    I am still none the wiser about runtime error 28, but like always, learning by trial and error is usually a good way to learn VBA coding.
    If my responses caused any offence, I apologise. I have learned much from many contributors on this website and I am grateful that people take time out of their day to help novice coders like myself.

  18. #18
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,616

    Re: Runtime error 28 Call Stack

    Glad to hear that
    and thanks for marking thread Solved amd for reputation point :-)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Runtime error '28'..... out of stack space solution!!
    By meus in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-12-2015, 05:58 AM
  2. [SOLVED] runtime error 5, invalid procedure call or argument ??
    By tintin007 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2014, 05:25 AM
  3. Runtime error 5 - Invalid Procedure or Call - Print Pdf
    By Barking_Mad in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-20-2014, 10:33 AM
  4. How do the experts pass an error up the call stack?
    By foxguy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-28-2013, 05:23 PM
  5. Runtime Error 28 Out of stack space = headache!
    By SportyJim1979 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-21-2012, 09:06 PM
  6. Runtime Error 5: Invalid procedure call or argument
    By Arasi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-07-2009, 11:49 AM
  7. error 28: out of stack space call function
    By ina in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-24-2006, 02:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1