Runtime Error 11 in VBA: “Division by zero,” explained and fixed

Error 11 — “Division by zero” — is VBA enforcing arithmetic: a division (or a Mod, or a power with a negative exponent) hit a denominator of zero. The zero is usually not typed anywhere — it's an empty cell read as 0, a count that found nothing, or a difference that cancelled out.

Find the zero

  1. Click Debug; on the highlighted line, hover the denominator expression. It will read 0 — the job is tracing why.
  2. If it comes from a cell, look at the cell: blank cells and cells containing text both evaluate to 0 in numeric context.
  3. If it's a computed value (a count, a total, a difference), print its inputs with Debug.Print just before the line — empty ranges and fully-filtered data are the common story.

The usual hidden zeros

  1. An average over an empty set — total ÷ count where count is 0 because the filter matched nothing.
  2. Percentages of a zero base — growth vs last period when last period was zero (or blank).
  3. A divisor cell left blank by an incomplete form or an import with missing rows.
  4. Integer division and Mod — a \ b and a Mod b obey the same rule; they hide in code that “doesn't divide anywhere.”
  5. Dates that subtract to zero used as a divisor (same-day start/end).

The fix

  1. Guard the division:
    If denom <> 0 Then
        result = numer / denom
    Else
        result = 0   ' or skip, or flag — decide what zero means for this report
    End If
  2. Decide the semantics deliberately. Sometimes the right answer for “average of nothing” is 0, sometimes blank, sometimes “not enough data.” The guard isn't complete until that choice is made — silently writing 0 into a report can be its own bug.
  3. Fix the data when the data is wrong — a denominator cell that should have been filled is a process issue; code guards keep the macro alive, and a logged warning keeps the issue visible.
Do not download anything for this error. Somewhere upstream, a zero was allowed to reach a division. One guard, placed where the zero is born or where it's used, ends it.

If it still happens

The denominator is being produced dynamically — a lookup, a count, a difference. Log the denominator and its two parents before every risky division for one run; the record that produces zero will identify itself, and with it, which assumption (“there's always at least one row”) the data broke.

Common questions

Can dividing by zero damage the workbook? No. The macro stops at the division; nothing is written by the failed statement itself. Data changed by earlier statements in the same run stays changed, as with any stopped macro.

Why does it fail only on some days? Because only some days produce the empty set — no sales, no rows, a zero base period. Data-dependent denominators are the whole story with this error.

Related errors

Runtime Error 6 · Runtime Error 5 · Runtime Error 13