Wauvel

Excel like a finance pro.

← The library

VBA · Objects

ActiveCell and Selection

The cell the cursor is on and whatever is selected; recorded macros lean on them, good code avoids them.

CommonDifficulty 1000 · Capable
Practice · 2 questions →

When to use it

ActiveCell is the cell with the cursor and Selection is whatever is selected. Recorded macros lean on them; deliberate code passes ranges explicitly so it works no matter where the user clicked.

The code

Code
ActiveCell.Value = 1
Selection.ClearContents

Worked examples

  • Use the cursor

    ActiveCell.Value = 1 Writes wherever the cursor is

    Fine for a utility macro run on a chosen cell.

  • Use the selection

    Selection.ClearContents Clears whatever is selected

    A "clear selected" button.

  • Guard

    If TypeName(Selection) <> "Range" Then Exit Sub Guards against a chart being selected

    Selection is not always a Range.

Worth knowing

  • For utilities the user runs on a selection they are appropriate; for automation, name the ranges.
  • Selection.Areas handles multiple selected blocks.
  • ActiveCell is a single cell even inside a large selection.

Where it goes wrong

  • Selection can be a shape or chart, so Selection.Value errors.
  • Macros depending on the active cell fail silently when run from the wrong place.

Related

Learn the moves here — or let Wauvel run them on your numbers.

Meet your AI CFO →

One CFO-grade Excel tip a week

A short, practical email for finance operators — functions, shortcuts, and the moves that save an afternoon. Free, unsubscribe anytime.