Quick Tip: Instant Find in the VBA IDE

Somehow I went more than 20 years writing code in VBA without knowing about this handy shortcut key.

Quick Tip: Instant Find in the VBA IDE

tl;dr: [Ctrl] + [F3]

Press [Ctrl] + [F3] in the VBA IDE to cycle through all instances of the current word within the same code module.

Additional Details

This tip comes to us from longtime Access MVP, Karl Donaubauer, who casually mentioned it in one of his rebuttals to my article on declaring variables closest to their first use:

I maintain that the variable is more noticeable if it is clearly visible at the beginning of the procedure and is quickly checked from there with Ctrl+F3 or similar. But that brings us back to the area of taste/style.

I've been working with VBA for well over 20 years, but I did not know about that shortcut key until I read Karl's comment.  Apparently, it's a very well-kept secret, as it does not even appear on this (not quite!) exhaustive list of VBA shortcut keys:

The Complete List of VBA Keyboard Shortcuts in Microsoft Excel | How To Excel

How It Works

You don't even need to have the whole word selected.  Simply place the cursor within the word you want to search for and press [Ctrl] + [F3].  The VBA editor will immediately find the next instance of that word within the same code module and select it.

Here are some other notes about the feature:

  • If there are no other instances of the word, the current word gets selected but nothing else happens.
  • The search wraps around to the beginning of the module if you press Ctrl + F3 on the last instance of the word.
  • The search is limited to the current code module, but is otherwise unaffected by scope.
  • The feature works within code comments.
  • If you have multiple words selected, it will perform an immediate search of the entire phrase.
  • [Shift] + [Ctrl] + [F3] searches backwards.
  • Backward searching does not automatically wrap around.  Instead, you get the dialog box shown below:

Special thanks to Karl Donaubauer for bringing this feature to my attention.

All original code samples by Mike Wolfe are licensed under CC BY 4.0