Share via


Watch Object

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Watches
Aa168103.parchild(en-us,office.10).gifWatch

Represents a range which is tracked when the worksheet is recalculated. The Watch object allows users to verify the accuracy of their models and debug problems they encounter. The Watch object is a member of the Watches collection.

Using the Watch object

Use the use the Add method or the Item property of the Watches collection to return a Watch object.

In the following example, Microsoft Excel creates a new Watch object using the Add method.  This example creates a summation formula in cell A3, and then adds this cell to the watch facility.

  Sub AddWatch()

    With Application
        .Range("A1").Formula = 1
        .Range("A2").Formula = 2
        .Range("A3").Formula = "=Sum(A1:A2)"
        .Range("A3").Select
        .Watches.Add Source:=ActiveCell
    End With

End Sub

You can specify to remove individual cells from the watch facility by using the Delete method of the Watches collection. This example deletes cell A3 on worksheet 1 of book 1 from the Watch Window. This example assumes you have added the cell A3 on sheet 1 of book 1 (using the previous example to add a Watch object).

  Sub DeleteAWatch()

    Application.Watches(Workbooks("Book1").Sheets("Sheet1").Range("A3")).Delete

End Sub

You can also specify to remove all cells from the Watch Window, by using the Delete method of the Watches collection. This example deletes all cells from the Watch Window.

  Sub DeleteAllWatches()

    Application.Watches.Delete

End Sub