> ## Content Index
> Fetch the complete content index at: https://nolongerset.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Watch Expression
- URL: https://nolongerset.com/watch-expression/
- Published: 2021-03-07T01:53:51.000Z
- Updated: 2026-05-08T13:06:02.000Z
- Description: A deeper than necessary dive into the exact expression evaluation behavior of the basic "Watch Expression" in VBA.
- Author: Mike Wolfe
- Tags: Watches, Advanced, Debugging, #Import 2026-05-20 02:59

This is the first in a series of articles that will dive into the behavior of the different Watch Types in VBA:

- **Watch Expression**
- Break When Value Is True
- Break When Value Changes

We'll focus on the first type in this article: **Watch Expression**. This most basic type of Watch will not force your code to halt the way the other two types can. This has important implications when it comes to [debugging performance](https://nolongerset.com/watching-and-waiting/). 

## Demonstration

To demonstrate the behavior of the different Watch Types, I'm going to use my own custom [Watch() method](https://nolongerset.com/watch-this/) to illustrate just how often these expressions are being evaluated.

### Sample Code

Here's the sample code I will be using for the demonstration:

```vba
#If VBA7 Then
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If

Dim MyVar As Integer

Function Watch(Val, Optional CalledFrom As String = "")
    Debug.Print Val, CalledFrom
    Sleep 1000   'Sleep for one second for demo purposes
    Watch = Val
End Function

Sub TestWatch()
    MyVar = 0
    Debug.Print "Alpha"
    Debug.Print "Bravo"
    MyVar = 2
    Debug.Print "Charlie"
End Sub
```

Here's the expression I will be watching. Note that each time this expression is evaluated, the value of **MyVar** will be printed to the immediate window, along with the current date and time.

```vba
Watch(MyVar, Now) = 2
```

Throughout this series of articles, the code itself and the expression being watched will remain the same. The only things I will be changing are:

- the Watch Type
- the setting of breakpoints
- method of code execution (e.g., \[F5\] "Run" vs. \[F8\] "Step Into")

## Watch Type: • Watch Expression

### Run Sub \[F5\] - No Breakpoints

In the first test, we're just running the test function using Run > Run Macro (F5):

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/03/image-10.png)

No timestamp written to the Immediate Window because the expression never got evaluated

### Run Sub \[F5\] - Breakpoints as indicated

In this next test, I've added a couple of breakpoints on the lines where I'm setting the value of MyVar. Here's the result:

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/03/image-11.png)

The expression is evaluated each time code execution halts; in this case, at each breakpoint

Notice that the expression is evaluated when the code halts, not when it starts. That's why at the first breakpoint, the value of MyVar is 2 (it's left over from the previous run). Then, at the second breakpoint, the value of MyVar is 0 (as set earlier in the function).

### Step Into \[F8\]

For the final test, I'm showing what happens when we step through the **TestWatch()** function one line at a time.

1. This is the starting point; I have not pressed F8 yet.
2. The first F8 press sets the next statement to the routine declaration line. The value of **MyVar** is 2 from the previous run. No lines of code have actually executed yet. However, the Watch expression has been evaluated.
3. The second F8 press executes the routine declaration line. Note that the value of **MyVar** is still 2 because the `MyVar = 0` line has not yet been executed.
4. The third F8 press executes the line that sets MyVar to zero. Note that the value of MyVar is now 0 in the immediate window.
5. The fourth F8 press prints "Alpha" to the immediate window. *And then* the Watch Expression is evaluated.
6. The fifth F8 press prints "Bravo" to the immediate window.
7. The sixth F8 press sets the value of **MyVar** to 2.
8. The seventh F8 press prints "Charlie" to the immediate window.
9. The eighth F8 press executes the End Sub line and exits the routine. After exiting the routine, the watched expression is evaluated one last time.

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/03/2021-03-06-20_26_01-mjw20-Window-1.png)

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/03/2021-03-06-20_26_14-mjw20-Window-1.png)

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/03/2021-03-06-20_26_20-mjw20-Window-1.png)

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/03/2021-03-06-20_26_25-mjw20-Window-1.png)

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/03/2021-03-06-20_26_31-mjw20-Window-1.png)

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/03/2021-03-06-20_26_37-mjw20-Window-1.png)

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/03/2021-03-06-20_26_43-mjw20-Window-1.png)

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/03/2021-03-06-20_26_49-mjw20-Window-1.png)

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/03/2021-03-06-20_26_54-mjw20-Window-1.png)

Stepping through the TestWatch function one line at a time

*Image by [JL G](https://pixabay.com/users/ractapopulous-24766/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=3732867) from [Pixabay](https://pixabay.com/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=3732867)*