"Out of Stack Space" Macro Error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to create a button which, when clicked on, will calculate the
formulas in the workbook. I have set the workbook to calculate manually. I
recorded the macro as follows:

Sub Calculate()
Calculate
End Sub

However, when I run the macro it gives the error message: Run-time error
'28' Out of stack space". Does anyone know what I am doing wrong? Is there
a better way to allow a user to click on a button to recalculate the cells as
opposed to hitting F9?

Thanks,

Adam
 
Adam,

You're calling Calculate inside of Calculate. It's a dog chasing its tail. Every call to
Calculate causes another stuff, each time putting more stuff on the stack until it's pushed
to the center of the earth. Then you get that error.

--
Earl Kiosterud
www.smokeylake.com

Note: Top-posting has been the norm here.
Some folks prefer bottom-posting.
But if you bottom-post to a reply that's
already top-posted, the thread gets messy.
When in Rome...
 
Adam,

I hit send before I was done.

Sub Calculate
Application.Calculate
End Sub

Or do this:

Sub CalculatePlease()
Calculate
End sub

The latter is preferable -- it's not a good idea to use Excel's names for your sub names.

Best form of all:

Sub CalculatePlease()
Application.Calculate
End Sub
--
Earl Kiosterud
www.smokeylake.com

Note: Top-posting has been the norm here.
Some folks prefer bottom-posting.
But if you bottom-post to a reply that's
already top-posted, the thread gets messy.
When in Rome...
-----------------------------------------------------------------------
 
Because your routine is calling itself recursively.
Try:

Sub Calculate()
Application.Calculate
End Sub

or:

Sub MyCalculate()
Calculate
End Sub

instead.
 
Back
Top