Skip to main content

Range.Dirty method

Table of contents
  1. Syntax
  2. Remarks
  3. Example

Designates a range to be recalculated when the next recalculation occurs.

Syntax

expression.Dirty

expression A variable that represents a Range object.

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, 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

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>