Class Watch (Excel VBA)
The class Watch represents a range that is tracked when the worksheet is recalculated. The Watch object allows users to verify the accuracy of their models and debug problems that they encounter.
Set
To use a Watch class variable it first needs to be instantiated, for example
Dim wtc As Watch
Set wtc = Application.Watches.Add(Source:=)
The following procedures can be used to set variables of type Watch: Watches.Item, Watches.Add and Application.Watches
For Each
Here is an example of processing the Watch items in a collection.
Dim wtcWatche As Watch
For Each wtcWatche In Application.Watches
Next wtcWatche
Delete
Deletes the object.
Parent
Returns the parent object for the specified object. Read-only.
Source
Returns a Variant value that represents the unique name that identifies items that have a SourceType property value of xlSourceRange, xlSourceChart, xlSourcePrintArea, xlSourceAutoFilter, xlSourcePivotTable, or xlSourceQuery.
Possible Values are xlSourceAutoFilter - An AutoFilter range, xlSourceChart - A chart, xlSourcePivotTable - A PivotTable report, xlSourcePrintArea - A range of cells selected for printing, xlSourceQuery - A query table (external data range), xlSourceRange - A range of cells, xlSourceSheet - An entire worksheet, xlSourceWorkbook - A workbook.If the SourceType property is set to xlSourceRange, this property returns a range, which can be a defined name. If the SourceType property is set to xlSourceChart, xlSourcePivotTable, or xlSourceQuery, this property returns the name of the object, such as a chart name, a PivotTable report name, or a query table name.
Watches.Add
Adds a range that is tracked when the worksheet is recalculated.
Syntax : expression.Add (Source)
Source: The source for the range.
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
Watches.Count
Returns a Long value that represents the number of objects in the collection.
Watches.Delete
Deletes the object.
Watches.Item
Returns a single Watch object from the collection.
Syntax : expression.Item (Index)
Index: The name or index number of the object.
Watches.Parent
Returns the parent object for the specified object. Read-only.