+ Reply to Thread
Results 1 to 21 of 21

Error:28 Out of Stack Space and I am out of options, What else can I do?

  1. #1
    Registered User
    Join Date
    03-30-2020
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    11

    Question Error:28 Out of Stack Space and I am out of options, What else can I do?

    Hi All
    I am a new user of this Forum and I started to use Excel about 5 years ago.
    I didn’t know anything about VBA coding back then, but after 2 years later on forums and asking allot around I was hooked and so everything was self-learned.

    3 years ago I was calculating some personal stuff that was very time consuming and I realize that had to use the VBA coding for automate the calculation process…

    The last 6 months I had the “Error 28: out of stack space“ issue
    and in those 6 months I try to clean up my code with less code lines overall in my Modules..

    I know it has to do with allot of repeating of my Call options
    Please Login or Register  to view this content.

    It’s was about 1500 Code lines and I shortened it down to 165
    But the Error 28 still comes back

    I have added also my Excel file with less codes:
    Module 1 is that main Procedure
    Module 2 is the calculator
    Module 3 is the Cell Value for Column B3 to B6 and Column N11 to N13
    Module 4 is that Cell Value and Color for Column B3 to B6
    Module 5 checks that value outcome after Module1 is done

    the main problem have is that this code that I have now makes sense I know it’s doing.
    But I don’t know how to use a different code with the same outcome and calculation structure that I have now.

    thank you in advance!

    I hope I did everything by the Forum rules

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    Breaking a program into multiple procedures can be an efficient way to program, provided the controlling procedure and any sub routines which call other procedures do not leave a trail of open procedures before accomplishing a task. Called procedures should do their individual tasks and then close, yielding back to the calling procedure as much as possible. If too many are left open while another procedure is called, you get the error because the memory stack can only handle so many variables and attributes at a time, So reviewing what your procedures are doing and seeing if you could yield back to the controlling procedure and let it make the call to the next procedure might solve your problem. I find that making a flow chart (block diagram) of the tasks and analyzing the logical steps helps in organizing how procedures interact.

    Here are the Microsoft suggestions for managing potential causes:

    1.Check that procedures are not nested too deeply.

    2.Make sure recursive procedures terminate properly.

    3.If local variables require more local variable space than is available, try declaring some variables at the module level. You can also declare all variables in the procedure static by preceding the Property, Sub, or Function keyword with Static. Or you can use the Static statement to declare individual static variables within procedures.

    4.Redefine some of your fixed-length strings as variable-length strings, as fixed-length strings use more stack space than variable-length strings. You can also define the string at module level where it requires no stack space.

    5.Check the number of nested DoEvents function calls, by using the Calls dialog box to view which procedures are active on the stack.

    6.Make sure you did not cause an "event cascade" by triggering an event that calls an event procedure already on the stack. An event cascade is similar to an unterminated recursive procedure call, but it is less obvious, since the call is made by Visual Basic rather than an explicit call in the code. Use the Calls dialog box to view which procedures are active on the stack.
    Last edited by JLGWhiz; 04-02-2020 at 10:25 AM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    03-30-2020
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    11

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    Quote Originally Posted by JLGWhiz View Post
    Breaking a program into multiple procedures can be an efficient way to program, provided the controlling procedure and any sub routines which call other procedures do not leave a trail of open procedures before accomplishing a task.

    Here are the Microsoft suggestions for managing potential causes:

    I have read that many times over and over again Microsoft
    But when I do that to split everything up in separate procedures then I will have millions and trillions of code lines

    Only 1 colors has about 576460752303423488 Calculations on 59 cells

    Imagine I want to use this with 58 colors more

    Maybe I need to try it out and see what it will do
    Last edited by JohanL66; 04-02-2020 at 04:28 PM.

  4. #4
    Valued Forum Contributor
    Join Date
    01-14-2013
    Location
    Austria
    MS-Off Ver
    2016 / 2019
    Posts
    339

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    What is your intention on this application? If you endless recursively call one or more functions the stack will be full. I could not see when this code is completely executed (finished).
    The address of a function call must be stored on a stack so that you can return to the calling function.
    At the end the stack overflow is not dependent on your codes size (number of lines).

  5. #5
    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: Error:28 Out of Stack Space and I am out of options, What else can I do?

    You only appear to have 5 different colour variations. Why not use Conditional Formatting and avoid VBA?
    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.

  6. #6
    Registered User
    Join Date
    03-30-2020
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    11

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    Quote Originally Posted by gue2013 View Post
    What is your intention on this application?
    The intention is make a calculation with the Algo that I have created with this type of structure
    I know what this Out of Stake Space mean Sir, but I don't know what I can change to prevent that happening without making allot of code lines
    I know that the stack overflow has nothing to do with Codes size but would you type billions of code lines when you can do it with 1% of that number?..
    the only problem I have is that I get this Stack Overflow....


    You only appear to have 5 different colour variations. Why not use Conditional Formatting and avoid VBA?
    The Excel will be very slow and also be very big..I mean really BIG
    It can not calculate what I need Sir

    Every change in 1 Cell the Module 1 has to run
    Last edited by AliGW; 04-06-2020 at 06:25 PM.

  7. #7
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,606

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    Please don't quote whole posts -- it's just clutter.*If you are responding to a post out of sequence, limit quoted content to a few relevant lines that makes clear to whom and what you are responding
    Ben Van Johnson

  8. #8
    Registered User
    Join Date
    03-30-2020
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    11

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    Sorry ProtonLeah i have changed on your request Sir

  9. #9
    Registered User
    Join Date
    03-30-2020
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    11

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    Please look at the picture
    So you can some small details what everything is or needs to do
    Attached Images Attached Images

  10. #10
    Valued Forum Contributor
    Join Date
    01-14-2013
    Location
    Austria
    MS-Off Ver
    2016 / 2019
    Posts
    339

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    I still do not understand why you do it but if you have an algorithm then you can generate a matrix of parameters (for each round)
    you know how many rounds you have to execute --> do .. while (may be you need a second loop or more loops inside this loop)
    Then you use a function inside these loops and hand over the parameter to get the result for each round
    is this possible?

  11. #11
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    At some key points in your code, add break points. Then use View -> View Call Stack to see currently active procedure calls.
    Ex: I added break point in your main procedure.
    0.JPG

    As you can see, there are more than one active process for each procedure.
    Looks like none of the process terminated and it just keeps growing until stack error is reached.

    This is what's causing your issue. Looking at your modules, you've defined very cell specific operation as individual subs.
    Though I didn't follow through on entire dependency... looks like you are unnecessarily nesting procedures for each condition.

    From your picture it isn't all that clear to me what your starting point is, and what your end goad of the code is.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  12. #12
    Registered User
    Join Date
    03-30-2020
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    11

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    Thank you all for your input guys

    I have found a way to solve this problem but I can not start the program where I left off

    I have to figure that out as well
    I need to do allot of testing and to break down the issues at hand..
    I will get back when I have a solution to solve the other issue..

    thanks guys

  13. #13
    Registered User
    Join Date
    03-30-2020
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    11

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    Is it not so that the Stack is to slow to clean while the procedures are running over and over again?
    I am using the same procedures over and over again so I have less Code-lines Sir

    There has to be a way to fix this

    I have tried a different way but its not working the way I want it to be
    I have added a picture that gives a better understanding about the structure about the Modules and calculations


    When you have questions please do so

  14. #14
    Valued Forum Contributor
    Join Date
    01-14-2013
    Location
    Austria
    MS-Off Ver
    2016 / 2019
    Posts
    339

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    The stack is just memory and this is fast, it never can be too slow for something.
    your problem is that you are calling a function inside a function inside a funtion ... and never com back.

    Therefore your stack is growing.

    you should call a function and return. in this case you put the address at which the function was called onto the stack and this address is used (stack is cleared) for further execution when the function returned.

  15. #15
    Registered User
    Join Date
    03-30-2020
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    11

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    Maybe that is what I miss in my coding, cause I have no clue how to do that Sir

    That is for more advanced VBA coder I believe..right?

    How do I return to a function, when the Function is called over and over again, what do mean with that

    "You should Call a Function and return"

    !!???

  16. #16
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    You can do this"
    Please Login or Register  to view this content.
    But this is not recommended and will cause you problems.
    Please Login or Register  to view this content.
    The second set of code is how you have your code set up. The first set is the correct way to call macros. I cannot rewrite your macros for you because I do not understand what your are trying to do. But you need to rearrange the way you are calling the macros so that each one completes its task and then returns the control to the main macro. You can call one of the sub routines more than once from the main macro if need be, but leaving them open as illustrated in the second set above will definitely give you a stack overflow error.

    To get a better understanding of the closing and yielding back principle, put these macros in a new workbook standard code module and use the F8 key to step through them. Watch how the yellow highlight moves from line to line and from macro to macro. Note the difference between set 1 and set 2. Do not run set 2 on automatic because it will be a perpetual loop and blow your memory stack.
    Last edited by JLGWhiz; 04-07-2020 at 11:37 AM.

  17. #17
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    See previous post.
    Last edited by JLGWhiz; 04-07-2020 at 11:41 AM.

  18. #18
    Registered User
    Join Date
    03-30-2020
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    11

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    Quote Originally Posted by JLGWhiz View Post
    See previous post.
    I did
    I have changed that do the Functions you gave me as an example

    Thanks for that mate

    Now look at the picture

    You can see that I have used 5 Colors for calculation

    1 picture have 4405 lines (No Error 28) and the other only 126 lines (With the Error 28)

    You can see the difference is HUGH!
    I only see the Code lines PROBLEM...And I do understand Error 28!
    There has to be a way where I can code the function in a certain way where I can repeat the same function without having the Error 28 issue

    Is there a way to get that issue solved without have to make allot of Lines of codes?
    Attached Images Attached Images

  19. #19
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    This is far from perfect, but it will illustrate the technique better than my previous post. The object is to use the a control macro to call the Info-Data macros. By using a criteria to determine when to call each Info_Data macro, you can remove the call of the next Info_Data macro from the previous one and just let the control macro do the calling. That will then allow each Info-Data macro to do its task and then close, even though those are calling additional macros. So long as there is not a perpetual loop of calls or a string of macros left open, the error 28 should go away. Talke a look at the way I organized the code and see if you can use that or something like that to redo what you have. You should not have to use 4000 lines of code to do your analysis.
    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    03-30-2020
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    11

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    I saw your structure

    I like it...I have already change some Functions..still i have bigger Code Sizes then I normally have with you show above...

    I have no Error for now
    I am going to short it more to see when I get it again..


    But still I have to find a way where I don't get the Error code 28 and still have a small Code Size


    I will get back when I have tested more options..

    thanks for your input Sir

  21. #21
    Registered User
    Join Date
    03-30-2020
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    11

    Re: Error:28 Out of Stack Space and I am out of options, What else can I do?

    @JLGWHiz thanks for your input man

    I have try to use your structure how to build these functions to get no Error 28
    So I had to fine tune that structure so I am sure i get all the calculations that I need over those 4 cell/Colors

    Look below the code that I have used
    And off course it gives me the Error 28 again but this way you can see how every cell and Cell Value including the colors is calculated..

    I did this so you can see how the sequence should be used, so that all calculations are running when a Cell Value/Color has changed on any Cell

    Please Login or Register  to view this content.

    1. Cell.Value changed (So called Active.Cell Example B6)
    2. All the cells above that Active.CELL will change their Value to all Black S's
    3. The Cell Value in N11 and below change their value to 1 again ( this starts from B6 but in this case the N11 will only go higher(Max 8) and the Cells below that will stay the same)
    4. Call Algorithm_2_49_Cells this will calculates the Cell.Values

    and then it all start over again

    You can see on the sheet when where starts in what B Cell and also in Column N from N11

    I hope this makes more sens

+ 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. Error 28 - Out of Stack Space
    By Beva07 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-11-2019, 11:05 AM
  2. out of stack space error
    By bezbid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-02-2019, 06:13 PM
  3. [SOLVED] Error 28 Stack Space
    By scrabtree23 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2015, 09:58 AM
  4. VBA Out of Stack Space Error 28
    By alexcapewell in forum Excel General
    Replies: 9
    Last Post: 10-13-2015, 07:01 AM
  5. Out of stack space error
    By lazyengineer in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-10-2015, 02:24 PM
  6. [SOLVED] Run TIme Error 28: Out of Stack Space
    By smciesl2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-22-2014, 01:21 PM
  7. Out of stack space error
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-20-2008, 03:47 PM

Tags for this Thread

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