简体   繁体   中英

How can I enable and disable expensive calculations in an Excel spreadsheet?

I use huge excel worksheets and they take forever to load because of cell calculations using macros and other formulas (over 5 minutes even if I have a good computer) . I was wondering if there was a way to save the excel files with the current cell values instead of calculating the cells each time I open the file.

What I am looking for is like a switch that would turn the calculations on and off so that when I need to use them I could set them to on, and when I am done, I could switch it to off and the cells would keep their current values.

Maybe I could create a macro that would do something like that, or maybe I am just dreaming and there is no other way around, so I should just sit and wait.

We have a similar problem.

This is what we use:

Function TurnOfCalcs()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
    Application.DisplayAlerts = False
End Function 

We turn off calculations, screenupdating, alerts and events while the initial data is loading and updating.

Once the streaming data from the sheet has finished we turn updates back on like so:

Function TurnOnCalcs()
   Application.ScreenUpdating = True
   Application.Calculation = xlCalculationAutomatic
   Application.EnableEvents = True
   Application.DisplayAlerts = True
End Function

You still have the udpate time but this means you don't' do updates after each single cell change, which should dramatically speed up your file loading times.

You can set the calculation options for Excel both via the GUI and via VBA: Application.Calculation = xlManual

Here is some more info... http://www.decisionmodels.com/calcsecretse.htm

Use:

Private Sub Workbook_Open()
Module1.TurnOff
End Sub

Then have a button than is assigned this macro

Sub Button1_Click()

If Application.EnableEvents = True Then
    TurnOff
Else
    TurnOn
End If

End Sub

Then have this in a module:

Public Sub TurnOn()
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub

Public Sub TurnOff()
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM