OnCalculate Property

Applies To

Application Object, Worksheet Object.

Description

Returns or sets the name of the macro that runs whenever you recalculate the worksheet. Read-write.

Remarks

Setting this property for a worksheet overrides any macro that may be set for the application.

Set this property to empty text ("") to remove the macro.

A macro set to run by the OnCalculate property is not run by actions taken by other macros. For example, a macro set by OnCalculate will not run if a macro calls the Calculate method, but will be run if you change data in a sheet set to calculate automatically or choose the Calc Now button.

Example

This example causes "my_Recalc_Macro" to run when you recalculate Sheet1.


Worksheets("Sheet1").OnCalculate = "my_Recalc_Macro"

This example disables the OnCalculate macro for Sheet1.


Worksheets("Sheet1").OnCalculate = ""