🚀The world's best VBA AI has evolved. ExcelMaster is now an autonomous Agent.Read more →

The ExcelMaster.ai Blog

VBA Worksheet_BeforeDoubleClick in Excel — Turn a Double-Click Into an Action (and Suppress Edit Mode)

VBA Worksheet_BeforeDoubleClick in Excel — Turn a Double-Click Into an Action (and Suppress Edit Mode)

Worksheet_BeforeDoubleClick is the event Excel fires the instant you double-click a cell, before it enters edit mode, and it hands you the Target cell plus a Cancel flag. Set Cancel to True to suppress edit mode and run your own action instead — toggle a checkmark, mark a row done, or drill down to detail. Learn how to scope it to one column with Intersect, why forgetting Cancel drops the cell into edit mode, and where the code must live.

Henry
VBA Worksheet_BeforeRightClick in Excel — Replace the Right-Click Menu (and Why Disabling It Isn't Security)

VBA Worksheet_BeforeRightClick in Excel — Replace the Right-Click Menu (and Why Disabling It Isn't Security)

Worksheet_BeforeRightClick is the event Excel fires the instant you right-click a cell, before the context menu appears, and it hands you the Target cell plus a Cancel flag. Set Cancel to True to suppress the built-in menu and run your own action or show a custom menu instead. Learn how to scope it with Intersect so you don't cripple Copy and Paste, why disabling right-click is UX rather than protection, and where the code must live.

Henry
VBA Workbook_BeforePrint in Excel — Block a Print, Stamp a Header, and the Print-Preview Gotcha

VBA Workbook_BeforePrint in Excel — Block a Print, Stamp a Header, and the Print-Preview Gotcha

Workbook_BeforePrint is the event Excel fires before anything in the workbook is printed, and it hands you a Cancel flag. Set Cancel to True and the print is blocked — validate before printing, or stop a draft going out. Learn why the event fires for Print Preview too (so heavy work makes preview crawl), why it runs once for the whole workbook rather than per sheet, why a silent Cancel is a bug, and where the code must live.

Henry
VBA Worksheet_Activate and Deactivate in Excel — Run Code When You Switch Sheets (and Why You Can't Cancel a Leave)

VBA Worksheet_Activate and Deactivate in Excel — Run Code When You Switch Sheets (and Why You Can't Cancel a Leave)

Worksheet_Activate fires when a sheet becomes the active one and Worksheet_Deactivate fires just as you leave it — the arrival and departure events for a sheet. The catch that defines them — unlike BeforeClose and BeforeSave, neither gives you a Cancel, so you can watch a sheet switch but you can't block it. Learn the refresh-on-view pattern, the bounce-back workaround, and sheet-level versus workbook-level handlers.

Henry
VBA Class Module in Excel — Build Your Own Object (Blueprint vs Instance, and the As New Trap)

VBA Class Module in Excel — Build Your Own Object (Blueprint vs Instance, and the As New Trap)

A VBA class module lets you define your own object type — a blueprint that bundles data and behaviour — then stamp out independent instances with New. The catch that trips everyone is that objects are reference types, so Set b = a makes both names point at the same instance, and Dim x As New hides a lazy-instantiation trap. Learn how the module name becomes the type name, when a class beats a Type, and how to avoid the classic New pitfalls.

Henry
VBA Type in Excel — Group Related Fields Into One Variable (User-Defined Types vs a Class)

VBA Type in Excel — Group Related Fields Into One Variable (User-Defined Types vs a Class)

A VBA Type — a user-defined type declared with Type ... End Type — bundles several related fields into one variable, so Name, Age and Salary travel together instead of as three parallel arrays. It is a value type, which means assigning one Type variable to another copies every field, unlike objects, which share. Learn where the declaration must live, why copy-not-share matters, and the exact point where you should reach for a class module instead.

Henry
VBA Property in Excel — Get, Let and Set (Controlled Access to a Class's Fields)

VBA Property in Excel — Get, Let and Set (Controlled Access to a Class's Fields)

Property Get, Let and Set turn a class field into a gate — a small procedure that runs your code whenever the outside reads or writes it, so you can validate input, compute values on the fly, or make a field read-only. The distinction that trips everyone is Let versus Set — Let assigns a value, Set assigns an object — and using the wrong one is a compile or run-time error. Learn the backing-field pattern, when a plain Public variable is the honest choice, and how to build a read-only property.

Henry
VBA ActiveCell in Excel — The One Cell With the Cursor (ActiveCell vs Selection, and When It Breaks)

VBA ActiveCell in Excel — The One Cell With the Cursor (ActiveCell vs Selection, and When It Breaks)

ActiveCell is a live pointer to the one cell that has the cursor right now — always exactly one cell, on the active sheet, sitting inside the current Selection. Learn how it differs from Selection, how to read and write it with .Value and .Offset, and the number-one reason it breaks — it follows whatever sheet and cursor the user left behind, so it is the wrong tool for code that is not about where the user is.

Henry
VBA Selection in Excel — Work With What's Highlighted (and Why It Isn't Always a Range)

VBA Selection in Excel — Work With What's Highlighted (and Why It Isn't Always a Range)

Selection is a live pointer to whatever is highlighted right now — usually a range of cells, but it can also be a chart, a shape, or nothing at all. That is why code that assumes Selection is a range crashes the moment a chart is selected. Learn how to loop the selected cells, handle multi-area selections with .Areas, guard with TypeName, and when to skip Selection entirely and name your range.

Henry
VBA Select vs Activate in Excel — Break the Macro Recorder's .Select Habit

VBA Select vs Activate in Excel — Break the Macro Recorder's .Select Habit

The macro recorder writes what your mouse does — Select a sheet, Select a cell, act on the Selection — because that is how a person works, not how code should. Learn the real difference between Select (highlight one or many cells) and Activate (set the one active cell), why almost every .Select is a slow, fragile detour you can delete, the rare times you genuinely need to select, and how to refactor recorder code to act on qualified range references directly.

Henry
VBA Worksheet_Change in Excel — Run Code When a Cell Is Edited (and the Infinite Loop to Avoid)

VBA Worksheet_Change in Excel — Run Code When a Cell Is Edited (and the Infinite Loop to Avoid)

Worksheet_Change is the event Excel fires every time a user edits a cell on the sheet, handing you the changed cell as Target. The trap that catches everyone — your handler writes a cell, that write fires the event again, and Excel loops forever. Learn the Application.EnableEvents fix, how to scope it with Intersect, why it ignores formula recalcs, and where the code must live.

Henry
VBA Worksheet_SelectionChange in Excel — Run Code When the Cursor Moves (Highlight the Active Row Without Lag)

VBA Worksheet_SelectionChange in Excel — Run Code When the Cursor Moves (Highlight the Active Row Without Lag)

Worksheet_SelectionChange is the event Excel fires every time the cursor moves — a click, an arrow key, an Enter. It hands you the new selection as Target, which makes cursor-following tricks like highlighting the active row possible. But it fires constantly, so heavy code makes the whole sheet lag. Learn the highlight-active-row pattern done right, why it can loop, and how to keep it featherlight.

Henry
VBA Collection in Excel — The Ordered, Growable List (and Why It Isn't a Dictionary)

VBA Collection in Excel — The Ordered, Growable List (and Why It Isn't a Dictionary)

A VBA Collection is an ordered list that grows as you Add to it — no ReDim, no size guessing. But it has four sharp edges beginners hit every time — it is 1-based not 0-based, you cannot overwrite an item (only Add/Remove), duplicate keys throw error 457, and it has no built-in Exists check. Learn when a Collection beats an Array or a Dictionary, and when it quietly costs you.

Henry