I noticed that whenever you invoke Application.Calculation to Automatic, it will recalculate the entire workbook. This is bad if your calculation procedure is only concerned to a particular worksheet. With the function below, I was able to control the scenario:
Public Const ONEONLY as Integer = 1
Public Const DISABLEALL as Integer = 2
Public Const ENABLEALL as Integer = 3
Sub SheetCalculation(iMethod As Integer, Optional sWorksheetName As String)
Dim ws As Worksheet
Application.Calculation = xlCalculationManual
Select Case iMethod
Case ONEONLY: 'To enable active sheet and disable the others
For Each ws In Worksheets
If ws.Name <> sWorksheetName Then
ws.EnableCalculation = False
Else
ws.EnableCalculation = True
End If
Next
Case DISABLEALL: 'To disable all sheets
For Each ws In Worksheets
ws.EnableCalculation = False
Next
Case ENABLEALL: 'To enable all sheets
For Each ws In Worksheets
ws.EnableCalculation = True
Next
Set ws = Nothing
End Select
Application.Calculation = xlCalculationAutomatic
End Sub
With the function above, you can disable/enable the other/all worksheets while doing calculation on the active sheet. This will save calculation time if the active sheet does not rely on any the other sheets at all.
Showing posts with label Excel. Show all posts
Showing posts with label Excel. Show all posts
Excel Tips: EnableCalculation Method
Posted @
4/09/2008 02:38:00 PM
2
comments
Categories: Excel
Optimize VBA
This page contains a number of tips for optimizing your VBA codes for Microsoft Excel 97 and 2003.
Posted @
3/04/2008 02:02:00 PM
1 comments
Categories: Excel, Tips and Tricks
Subscribe to:
Posts (Atom)
.jpg)