Calculation:
is a property which determines mode of calculation in Excel. It Returns or sets an XlCalculation value that represents the calculation mode. There are three types calculation modes available in Excel which can be set as default by the user. By default Automatic Calculation is set. Apart from setting user given right to perform force Excel to perform calculation which is also called Hard Calculate. We will look into each in this article.

Set Calculation Mode:
- Navigate Formulas tab
- Locate Calculation group
- Click Calculation Options dropdown
- Select appropriate calculation mode
Calculation mode is an workbook level behavior which remains through out the workbook life until it is changed by the user.
Automatic: its default calculation made where excel determines when to perform calculations on a workbook like, when formulas are dragged or copied from one location to another, source of your tables are updated, some custom functions detects change in the argument supplied in etc.
Automatic Except for Data Tables: also known as Semi Calculation mode this mode determines that excel will perform automatic calculation as mentioned above but Data Tables will not change. If you want to refresh everything then you have to use hard refresh.
Manual: excel leaves changes to be updated in user’s hand this is useful when you are dealing lots of formulas in your sheet with bulk data. If excel sets to automatic mode in this scenario making one change will perform calculation over entire sheet and will take time which turns annoying.
Hard refresh: not matter what calculation mode set to, hard refresh override the calculation rule and perform real time calculations it can be classified as:
- Calculate Now: this a method which forces Excel to ignore calculation mode and perform calculation immediately. It performs calculation over entire workbook.
- Calculate sheet: this is similar to Calculate Now method but refresh scope remains to active sheet.
- Calculate Full: it instructs excel to perform force calculation on all open workbook
- Calculate Full and Rebuild: instructs excel to perform force calculation on all open workbooks and rebuild dependencies
Lets understand some code to automate the same using. Considering for Dot Net I am using VSTO using C# and VB style code:
Prerequisites:
- Visual Studio 2015 or above having Microsoft Office for Developer Tool installed
- Create Excel Addin in C# or VB code style (Visual Studio Tools for Office)
- Excel 2010 or above
- Create a ribbon designer and put button
C# code example: Calculation mode
private void btnCalculationMode_Click(object sender, RibbonControlEventArgs e) { //auto calculaton mode Globals.ThisAddIn.Application.Calculation = excel.XlCalculation.xlCalculationAutomatic; //Semi calculation Globals.ThisAddIn.Application.Calculation = excel.XlCalculation.xlCalculationSemiautomatic; //Manual calculation Globals.ThisAddIn.Application.Calculation = excel.XlCalculation.xlCalculationManual; }
C# code example: Hard Calculate
private void btnHardCalculate_Click(object sender, RibbonControlEventArgs e) { //Hard calculate entire workbook Globals.ThisAddIn.Application.Calculate(); //Full calculate Globals.ThisAddIn.Application.CalculateFull(); //Calculate and rebuild Globals.ThisAddIn.Application.CalculateFullRebuild(); //Get worksheet reference excel.Worksheet oWorksheet = Globals.ThisAddIn.Application.ActiveSheet; //calculate sheet oWorksheet.Calculate(); }
VB.Net code example: Calculation mode
Private Sub btnCalculationMode_Click(sender As Object, e As RibbonControlEventArgs) Handles btnCalculationMode.Click 'Auto calculation Globals.ThisAddIn.Application.Calculation=excel.XlCalculation.xlCalculationAutomatic 'Semi calculation Globals.ThisAddIn.Application.Calculation=excel.XlCalculation.xlCalculationSemiautomatic 'Manual calculation Globals.ThisAddIn.Application.Calculation=excel.XlCalculation.xlCalculationManual End Sub
VB.Net code example: Hard calculation
Private Sub btnHardCalculate_Click(sender As Object, e As RibbonControlEventArgs) Handles btnRemoveArrows.Click 'Calculate workbook Globals.ThisAddIn.Application.Calculate() 'Calculate full Globals.ThisAddIn.Application.CalculateFull() 'Rebuld all dependencies Globals.ThisAddIn.Application.CalculateFullRebuild() 'Bind worksheet object reference Dim oWorkSheet as excel.Worksheet oWorkSheet = Globals.ThisAddIn.Application.ActiveSheet 'Calculate worksheet oWorkSheet.Calculate() End Sub
VBA code example: Calculation mode
Public Sub CalculationMode() 'Automatic calculation mode Application.Calculation = xlAutomatic 'Semiannual mode Application.Calculation = xlSemiautomatic 'Manual mode Application.Calculation = xlManual End Sub
VBA code example: Hard refresh
Public Sub HardRefresh() 'Force sheet calculate ActiveSheet.Calculate 'Hard calculate Application.Calculate 'Full calculate Application.CalculateFull 'Calculate rebuild Application.CalculateFullRebuild End Sub
Next >> Refresh All in Excel