Vba Error: out of Stack Space

Vba Error: out of Stack Space

I have a very simple macro in an Excel sheet, to allows users to recalculate.

I have no other macros/code in the workbook, and only this work book open

Sub Calculate()
    Calculate
End Sub

This is activated by a button.

However, when pressed I get two error boxes, see image.

What does Out of stack space mean ? And how do I resolve this issue ?

I have looked on this website:

It says I may have too many funtions ?? This macro used to work fine, and it is hardly doing a lot so cannot understand the issue.

I am able to calculate the sheet using the option under the formulas tab.

4

2 Answers

The function you have define is recursive, calling itself unconditionally until the stack is filled with all the calls.

You should change the name of your subroutine, eg:-

Sub Calc()
    Calculate
End Sub

If you link Calc() to the button, you avoid any recursion.

4

You're calling Calculate inside of Calculate. Every call to Calculate causes another call to Calculate, which will then call Calculate... Then eventually you get that error when the stack fills up.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.