Runtime Error 13 in Excel VBA: “Type mismatch,” explained and fixed

Error 13 — “Type mismatch” — means VBA was handed the wrong kind of data: text where a number was expected, a number where a date was expected, a whole range where a single value belonged. The code usually looks fine. The data is what surprises it.

What it means

VBA variables and functions expect specific types. When a value cannot be converted to the expected type — the characters "abc" into a number, an error value like #N/A into anything, a multi-cell range into a single number — VBA stops with error 13. It is a data problem far more often than a code problem.

Find the exact line first

  1. When the error appears, click Debug. The failing line highlights in yellow.
  2. Hover the mouse over each variable on that line — the tooltip shows its current value. One of them will look wrong for how it's used: text in a numeric variable, an empty cell, an error value.
  3. If the line reads from a cell, go look at that cell. Numbers stored as text (left-aligned, green triangle) and error values are the usual suspects.

The usual causes, most common first

  1. A cell contains text where the code expects a number or date — including numbers stored as text and cells containing things like “N/A” typed by hand.
  2. The cell contains an Excel error value (#N/A, #VALUE!, #REF!). Reading it into a typed variable raises 13 instantly.
  3. A range is assigned where a single value belongs — x = Range("A1:A10") instead of one cell.
  4. Dates in the wrong format — a date stored as text in a format VBA's conversion doesn't recognise, often different on different PCs because of regional settings.
  5. An array or object assigned to a plain variable without Set/indexing.

The fix

  1. Fix the data if the data is wrong. Convert text-numbers to real numbers (select the cells → the green-triangle menu → Convert to Number), and replace error values at the source formula.
  2. Guard the read in code when the data can't be trusted:
    If IsNumeric(Range("A1").Value) Then
        total = total + CDbl(Range("A1").Value)
    End If
  3. Check for error values before using a cell: If IsError(Range("A1").Value) Then handles the #N/A family.
  4. Use explicit conversions deliberately — CDbl(), CDate(), CStr() — so the conversion (and its failure) happens where it's visible, not silently inside an expression.
Do not download anything for this error. Error 13 is caused by data meeting code inside Excel. “Runtime repair” tools and registry cleaners cannot change what is typed in a cell.

If it still happens

Log the inputs: add a temporary line before the failing one that writes the variable values to the Immediate window (Debug.Print). Data-dependent errors always surrender to seeing the actual values. If the macro comes from an add-in or a colleague, send them the failing line and the values — that is the whole diagnosis in one message.

Common questions

Why does error 13 happen on one computer but not another? Usually regional settings: dates and decimal separators stored as text convert differently depending on the PC's locale. The file's data is interpreted by each machine's own settings.

Can error 13 corrupt a workbook? No. The macro stops; the workbook is not damaged by the error itself. Save problems only arise if a half-finished macro had already changed data before it stopped.

Related errors

Runtime Error 94 · Runtime Error 1004 · Runtime Error 6