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
Related
I have a complex Excel with lot of tables and formulas.
I stop and resume calculations via VBA code:
Turn OFF calculations:
ActiveSheet.EnableCalculation = False
Application.Calculation = xlCalculationManual
Turn ON calculations:
ActiveSheet.EnableCalculation = True
Application.Calculation = xlCalculationAutomatic
Application.Calculate 'This line calculates all open books and is not strictly necessary.
But still the cells are not calculated.
They are only calculated when I edit each cell with double click and hit Enter (one by one!).
The code doesn't give me any errors and works perfectly on simple books.
The problem is "EnableCalculation" method.
If I remove it, then the book works perfect. So simply toggle ON/OFF calculations with xlAutomatic/xlManual, like this:
Turn OFF calculations:
Application.Calculation = xlCalculationManual
Turn ON calculations:
Application.Calculation = xlCalculationAutomatic
I have a workbook that is designed to essentially operate as a standalone application. All sheets are protected, the individual excel tabs are hidden, and the top excel ribbon is hidden as well for the entire workbook.
The following VBA code performs the above procedures and is applied to every sheet within the workbook.
Sub masque()
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
ActiveWindow.DisplayHeadings = False
ActiveWindow.DisplayGridlines = False
ActiveWindow.DisplayWorkbookTabs = False
Application.DisplayFullScreen = True
Application.DisplayStatusBar = Not Application.DisplayStatusBar
Application.WindowState = xlMaximized
ActiveWindow.WindowState = xlMaximized
Application.DisplayFormulaBar = False
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
I want to use the following code as a button to override the prior code in order for an individual to easily switch between an "editor" mode and "user mode"
Sub masteredit()
Application.ScreenUpdating = False
ActiveWindow.View = xlNormalView
ActiveWindow.DisplayHeadings = False
ActiveWindow.DisplayGridlines = False
ActiveWindow.DisplayWorkbookTabs = False
Application.DisplayStatusBar = False
ActiveWindow.DisplayHorizontalScrollBar = True
ActiveWindow.DisplayVerticalScrollBar = True
ActiveWindow.DisplayWorkbookTabs = True
Application.DisplayFullScreen = False
Application.DisplayFormulaBar = True
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"
Application.ScreenUpdating = True
What is a good way to accomplish this?
well, you could have a predermined type of user, for example, by default the app will be for user_mode. So you use a special sub called auto_open(), that will be run each time you open the workbook. So we have
sub auto_open()
call masque
end sub
And you can add buttons whenever you want to change between editor mode and user mode. You can put sub auto_open() in any module you want, because it is detected as special by Vba
Solved the issue.
I forgot I had the following code on every sheet in the workbook.
Sub Worksheet_Open()
Call masque
End Sub
Sub Worksheet_Activate()
Application.ScreenUpdating = False
Call masque
Application.ScreenUpdating = True
End Sub
Therefore, any time I tried to navigate to a different sheet, the masque would be applied.
To solve my issue, I removed the prior code from every page. I then added a checkbox on my "Home" page that used the following code.
Sub Worksheet_Open()
Call masque
End Sub
Sub Worksheet_Activate()
Application.ScreenUpdating = False
Call masque
Application.ScreenUpdating = True
End Sub
This way, when you open up the workbook the masque is automatically applied. However when you click the checkbox you enter editor mode and the masteredit sub is applied. And when it is unchecked, the masque is once again applied.
I'm trying to create a hotkey that will toggle Application.ScreenUpdating. I just learned that the newer Excel versions automatically reset Application.ScreenUpdating to true after running a macro which is good 99.99% of the time except I don't want that to happen I want it to be persistent. Is there anyway for me to keep Application.ScreenUpdating = False?
Sub suspend_screen_update()
MsgBox "1st " & Application.ScreenUpdating
If Application.ScreenUpdating = True Then
Application.ScreenUpdating = False
Else
Application.ScreenUpdating = True
End If
MsgBox "2nd " & Application.ScreenUpdating
End Sub
Private Sub hk_toggle_screen_update()
Application.OnKey "{F1}", suspend_screen_update
End Sub
Why? My boss sometimes request that I only use Excel, nothing else, to manipulate a lot of data. Excel can be super slow if not crash when the data gets really big. I'm trying to save us time by creating this hotkey.
Newbie here.
I'm trying to delete a column using vba and it is taking a HUGE amount of time.
Sub Add_Delete()
Application.ScreenUpdating = False
Workbooks("f.xlsx").Sheets("g").Columns("FD:FD").EntireColumn.Delete
End Sub
There are about 20,000 rows with a total of amount 230 columns. There are no calculations being performed. Just data
What am I doing wrong? Thanks in advance!
If it is slow manually also turn off calculation before running it, then turn it back on.
Sub Add_Delete()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Workbooks("f.xlsx").Sheets("g").Columns("FD:FD").EntireColumn.Delete
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
add screen updating back in also... ;-)
My macro updates a large spreadsheet with numbers, but it runs very slowly as excel is rendering the result as it computes it. How do I stop excel from rendering the output until the macro is complete?
I use both of the proposed solutions:
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
...
...
...
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.ScreenUpdating = False
And of course set it back to True again when you've finished, even if an error is raised.
Example:
Public Sub MyMacro
On Error GoTo ErrHandler
Application.ScreenUpdating = False
... do my stuff that might raise an error
Application.ScreenUpdating = True
Exit Sub
ErrHandler:
Application.ScreenUpdating = True
... Do something with the error, e.g. MsgBox
End Sub
I also prefer to use both of the proposed solutions,
but also keeping the users previous calculation mode.
For this particular application this might be no biggie,
but it's usually best practice to let the users have their settings restored after your procedure is finished:
Application.ScreenUpdating = False
PreviousCalcMode = Application.Calculation
Application.Calculation = xlCalculationManual
...
...
...
Application.Calculation = PreviousCalcMode
Application.ScreenUpdating = True
NB. It would also be worth your time to insert some error handling that turns on Application.ScreenUpdating should an error occur in your otherwise brilliant code ;)
If memory serves me right, Excel will not show any errormessages etc when ScreenUpdating = false.
Something like this:
Sub DoSomeThing
On Error Goto DisplayError
Application.ScreenUpdating = False
PreviousCalcMode = Application.Calculation
Application.Calculation = xlCalculationManual
...
...
...
Application.Calculation = PreviousCalcMode
Application.ScreenUpdating = True
Exit Sub
DisplayError:
Application.Calculation = PreviousCalcMode
Application.ScreenUpdating = True
MsgBox Err.Description
End 'This stops execution of macro, in some macros this might not be what you want'
'(i.e you might want to close files etc)'
End Sub
Building upon Joe and SeeR (this uses old syntax so it's compatible with VBA of Office 2000):
On Error Goto AfterCalculation
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
...
AfterCalculation:
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
You can turn off automatic calculation in the options dialog, it sets it so that it only calculates when you press F9.