> ## 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.

# Quick and Dirty For Loops in the Immediate Window
- URL: https://nolongerset.com/for-loops-immediate-window/
- Published: 2022-02-22T02:18:05.000Z
- Updated: 2026-05-08T12:59:30.000Z
- Description: Did you know that you can write and execute entire For Loops in the VBA Immediate Window?
- Author: Mike Wolfe
- Tags: Hidden Features, #Import 2026-05-20 02:59

Sometimes I want to loop through a set of items while I'm developing, troubleshooting, or debugging some code and it's not worth creating an actual Function or Sub routine. In those situations, I like to use the [end-of-statement colon character](https://docs.microsoft.com/en-us/openspecs/microsoft%5Fgeneral%5Fpurpose%5Fprogramming%5Flanguages/ms-vbal/7ef9ae86-dfdb-47f1-b53b-ef0c2ea9f8ed) (`:`) to **execute multiple statements–**including entire For loops**–in a single line of the Immediate Window**.

Here's an example:

```vba
For i = 0 To CurrentDB.TableDefs.Count - 1: ?i, CurrentDB.TableDefs(i).Name: Next i
```

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

The single line of code above is equivalent to the following traditional code:

```vba
For i = 0 To CurrentDB.TableDefs.Count - 1
    Debug.Print i & vbTab & CurrentDB.TableDefs(i).Name
Next i
```

---

*I feel obliged to mention that while the code sample from the top of this article is perfectly valid syntax that you could use in a traditional code module, it's horribly unreadable\* and should only be used for "quick and dirty" development use in the Immediate Window where it's guaranteed to be gone forever as soon as you exit the application (or overload the Immediate Window buffer).*  
  
\* *Kind of like this paragraph*

*Image by [It is not permitted to sell my photos with StockAgencies](https://pixabay.com/users/lmoonlight-236255/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=3260697) from [Pixabay](https://pixabay.com/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=3260697)*