"Out of Stack Space" Macro Error

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
 
E

Earl Kiosterud

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...
 
E

Earl Kiosterud

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...
-----------------------------------------------------------------------
 
S

Stephen Bye

Because your routine is calling itself recursively.
Try:

Sub Calculate()
Application.Calculate
End Sub

or:

Sub MyCalculate()
Calculate
End Sub

instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top