Runtime Error 13: Type Mismatch (Trying to perform math on a string variable)

Runtime Error 13 occurs when an Excel VBA macro attempts to perform a mathematical operation on a variable or cell value that contains non-numeric text. This abrupt halt stops execution immediately, leaving automated workflows incomplete and threatening data integrity if upstream processing remains uncommitted. Resolving it requires identifying where text or cell errors enter your numeric expressions and applying proper type casting and validation.

Fast-Fix: The 45-Second Solution

Runtime Error 13 triggers because VBA cannot coerce a string variable containing text, symbols, or empty spaces into a numeric data type during arithmetic. To fix it immediately, wrap your variable in an IsNumeric() check before evaluating math, or use explicit conversion routines. For example, change total = val1 + val2 to If IsNumeric(val1) Then total = CDbl(val1) + val2.

Quick Risk Snapshot

  • Severity Tier: Moderate (halts code execution immediately, but does not corrupt unopened files).
  • Safe to Ignore?: No. The macro terminates abruptly on the breaking line, skipping subsequent code and leaving calculation updates or sheet changes half-finished.
  • Most Common Cause: Attempting math (+, , , /) on a string variable that contains letters, currency symbols, spaces, or an empty string ("").
  • Secondary Cause: Reading a worksheet cell containing an error value (#N/A, #VALUE!, #REF!) directly into a numeric variable.
  • Rare Cause: Passing incompatible array elements or Object properties into mathematical functions.

Low Risk vs. High Risk

  • Low Risk: The error occurs during a single-line macro test or a standalone utility script where no database, pivot source, or financial ledger has been modified prior to the crash.
  • High Risk: The error occurs inside a loop processing thousands of database rows, financial transactions, or automated email triggers after Application.ScreenUpdating or Application.Calculation has been disabled, leaving Excel in a suspended state with partial data writes.

Common Confusion Fix

  • Runtime Error 13 vs. Runtime Error 6 (Overflow): Type Mismatch means the data type is incompatible (trying to multiply text). Overflow means the data type is correct (numeric), but the number exceeds the storage limit of the variable type (for instance, assigning 50,000 to an Integer variable). For details on fixing overflow conditions, see Runtime Error 6: Overflow (Variable value exceeds the Integer limit—use Long).
  • Runtime Error 13 vs. Runtime Error 91 (Object Variable Not Set): Type Mismatch relates to data type compatibility. Error 91 occurs when referencing an object (like a Range or Worksheet) that has not been instantiated with the Set keyword.
  • Runtime Error 13 vs. Excel #VALUE! Worksheet Error: #VALUE! is a cell formula calculation error rendered on the spreadsheet interface. Runtime Error 13 is a VBA engine execution halt that completely stops code processing until resolved.

What To Do Right Now

  1. Identify the Breaking Line: Click Debug on the error message window to open the VBA editor with the failing line highlighted in yellow.
  2. Inspect Variable Values: Hover your mouse over each variable in the highlighted line, or use the Immediate Window to evaluate their current contents and data types. For step-by-step guidance on evaluating live variables, see How to use the Immediate Window to debug variable values in real-time.
  3. Sanitize Data Inputs: Add IsNumeric() conditions before executing math. If processing user input from UserForms, implement input validation routines prior to calculation. See Handling errors in UserForms: Validating text box input before it breaks the code.
  4. Handle Cell Error Values: Check for cell errors using IsError() before assigning cell values to numeric variables, especially when pulling from lookup formulas. See Troubleshooting VLOOKUP and MATCH when called via WorksheetFunction.
  5. Enforce Strict Variable Declarations: Add Option Explicit at the top of every module to force explicit variable typing and avoid accidental Variant conversions. See “Variable not defined”: Why you must use Option Explicit.

Hard-Stop Triggers

  • Yellow Highlight on Unsaved Workbooks: If the debugger breaks inside a macro that has already deleted or altered cells without saving a backup copy, do not save over the primary file.
  • Loop Counter Stalls: If the error occurs inside a loop that alters active data structures, stop execution immediately and roll back changes from a backup copy.
  • Disabled Screen Updating or Calculation: If Excel stops updating its screen or recalculating formulas after a crash, execute a reset script before continuing manual edits.

Symptom Escalators

Final Calculation

Runtime Error 13 is a straightforward type mismatch issue that is easily resolved by validating variable inputs before passing them into mathematical calculations. By placing IsNumeric() checks around vulnerable variables, explicitly converting strings using functions like CDbl or CLng, and enforcing Option Explicit across all modules, you eliminate type mismatch crashes entirely and maintain robust, fail-safe macro automation.