Dirty Method

Microsoft Excel Visual Basic

expression.Dirty

expression    Required. An expression that returns one of the objects in the Applies To list.

Remarks

The Calculate method forces the specified range to be recalculated, for cells that Microsoft Excel understands as needing recalculation.

If the application is in manual calculation mode, using the Dirty method instructs Excel to identify the specified cell to be recalculated. If the application is in automatic calculation mode, using the Dirty method instructs Excel to perform a recalculation.

Example

In this example, Microsoft Excel enters a formula in cell A3, saves the changes, and then recalculates cell A3.

Sub UseDirtyMethod()

    MsgBox "Two values and a formula will be entered."
    Range("A1").Value = 1
    Range("A2").Value = 2
    Range("A3").Formula = "=A1+A2"

    ' Save the changes made to the worksheet.
    Application.DisplayAlerts = False
    Application.Save
    MsgBox "Changes saved."

    ' Force a recalculation of range A3.
    Application.Range("A3").Dirty
    MsgBox "Try to close the file without saving and a dialog box will appear."

End Sub