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 ?enter image description here

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like