An implementation of Visual Basic that is built into Microsoft products.
Yes. VBA can control both when Excel recalculates and what gets recalculated.
Key options:
- Set calculation mode
Excel supports three modes:
- Automatic
- Automatic Except Tables
- Manual
- Trigger calculation from VBA
Use these methods depending on scope:
Application.Calculate ' all open workbooks Worksheets(1).Calculate ' one worksheet Worksheets(1).Rows(2).Calculate ' a specific range - Run code after recalculation
If logic should run when a sheet finishes recalculating, use the worksheet event:
Private Sub Worksheet_Calculate() Columns("A:F").AutoFit End Sub - Run code when any sheet in a workbook recalculates
Use the workbook-level event:
Private Sub Workbook_SheetCalculate(ByVal Sh As Object) With Worksheets(1) .Range("A1:A100").Sort Key1:=.Range("A1") End With End Sub - Application-wide recalculation event
To respond after any worksheet recalculates or chart data changes, use
Application.SheetCalculate.
Notes:
- In Automatic Except Tables, data tables are not recalculated automatically; they are recalculated by pressing F9 or by an equivalent programmatic calculation operation.
- For performance tuning,
Range.Calculateresolves dependencies within the range, whileRange.CalculateRowMajorOrdercalculates left-to-right, top-to-bottom and ignores dependencies. - Conditional format evaluation can also be controlled with
Worksheet.EnableFormatConditionsCalculation.
A practical pattern is:
- switch Excel to Manual calculation,
- make VBA changes,
- call
Worksheet.CalculateorApplication.Calculateonly when needed.
References: