A type mismatch error in Excel (run-time error 13) means a formula, macro, or data operation is trying to use a value of the wrong data type — for example, treating text like a number or passing a range where a single value is expected. The fastest fix is to identify the exact cell or line causing it, then convert the value to the correct type or adjust the formula or code to handle both types. This guide walks through diagnosing and resolving it for both formulas and VBA macros.

What You'll Need

  • Excel workbook with the error (any recent version; steps are for desktop Excel on Windows or Mac — the ribbon labels can differ slightly by version and region)
  • Access to the VBA editor if the error comes from a macro (Alt+F11 on Windows, Fn+Option+F11 on Mac)
  • Basic awareness of which cells contain numbers versus text

Step-by-Step

  1. Reproduce the error and note where it occurs. If it is a formula error, click the cell with the error and read the formula in the formula bar. If it is a VBA run-time error 13, click Debug when the dialog appears — the highlighted line is the culprit. Write down the cell reference or the variable name involved.
  2. Check the data type of the suspect cell. Select the cell and look at the alignment: numbers align right by default, text aligns left. You can also use =ISNUMBER(A1) or =ISTEXT(A1) in an empty cell to confirm. For a quick visual scan, apply a filter and look for cells with a green triangle (number stored as text).
  3. Convert text-that-looks-like-a-number into a real number. Select the range, then use Data > Text to Columns and click Finish — this re-parses each cell. Alternatively, enter 1 in an empty cell, copy it, select the range, and use Paste Special > Multiply. Both methods turn text numerals into numbers without retyping.
  4. Fix formulas that mix types. If a formula like =A1+B1 fails because B1 contains text, wrap the text value with VALUE() or use IFERROR to handle it: =IFERROR(A1+VALUE(B1),""). For lookups, ensure the lookup value and the lookup column are the same type — a common cause is a number in one and text in the other.
  5. Adjust VBA code that assumes a type. In the highlighted line, check variable declarations. If a variable is declared as Integer or Long but the cell contains text, either change the declaration to Variant or convert the value with CLng(), CDbl(), or CStr() as appropriate. For example, replace myNum = Range("A1").Value with myNum = Val(Range("A1").Value) if you expect text numerals.
  6. Handle empty cells and errors in code. A blank cell read into a numeric variable can also trigger type mismatch. Add a check: If IsNumeric(Range("A1").Value) Then ... before assigning. For ranges, use For Each cell In Range("A1:A10") and test each cell with IsNumeric.
  7. Re-test the formula or macro. Press F9 to recalculate formulas, or run the macro again. If the error persists, use the VBA Immediate Window (Ctrl+G) to print variable types: ?TypeName(myVar) shows the current type and helps spot unexpected text.
  8. Clean the source data if it comes from an import. CSV and text imports often store numbers as text. After importing, use Power Query (Data > Get Data) and set the column data type explicitly to Whole Number or Decimal Number before loading — this prevents mismatches downstream.

Common Mistakes

  • Assuming a cell is numeric because it looks numeric — leading apostrophes or spaces make it text. Use =ISNUMBER() to confirm.
  • Using Val() in VBA on values with commas or currency symbols; it stops at the first non-numeric character and can return 0 silently.
  • Forgetting that Range.Value returns a Variant, while Range.Text always returns a string — mixing them in comparisons causes mismatches.
  • Converting an entire column with Paste Special > Multiply when some cells contain genuine text labels; those become errors. Work on a copy first.
  • Declaring VBA variables as specific types without checking the data source — use Variant when the type is uncertain, then convert after validation.

Tips

  • Use TYPE() in a worksheet cell to return a number code for the data type (1 = number, 2 = text, 4 = logical, 16 = error), which is handy for auditing.
  • In VBA, add Option Explicit at the top of every module to catch undeclared variables early — many type mismatches come from typos that create a new Variant variable.
  • When building formulas that concatenate numbers and text, use TEXT() to control formatting rather than relying on implicit conversion.
  • Keep a helper column with =ISNUMBER(A1) next to imported data to quickly spot text numerals before they break calculations.

Troubleshooting

If the error still appears after converting cells, check for hidden characters. A non-breaking space (CHAR(160)) is common in web-copied data and survives TRIM. Use =CLEAN(TRIM(SUBSTITUTE(A1,CHAR(160)," "))) to strip it. For VBA, step through the code with F8 to watch each variable in the Locals window — the moment a variable shows a string where you expect a number, you have found the line. If the error only occurs on some rows, filter for blanks and text in the numeric column; empty cells passed to a numeric variable can also cause a mismatch. Finally, if the workbook uses links to external files, refresh those links (Data > Edit Links > Update Values) — stale links can return error values that propagate as type mismatches.

Frequently Asked Questions

What does "type mismatch" mean in Excel?

It means an operation expected one kind of data (usually a number) but received another (usually text), or a VBA procedure received an argument of the wrong type.

Why does my formula work in some rows but not others?

Those rows likely contain text instead of numbers — often from imported data or a stray apostrophe. Check with =ISNUMBER() and convert the affected cells.

How do I fix run-time error 13 in a macro?

Click Debug, inspect the highlighted line, and check the variable types with TypeName() in the Immediate Window. Convert values with CStr, CLng, or CDbl, or declare the variable as Variant.

Can a blank cell cause a type mismatch?

Yes, in VBA if a blank is assigned to a numeric variable. Test with IsNumeric or IsEmpty before assigning.

Does Text to Columns always fix text numbers?

It fixes most cases, but cells with non-breaking spaces or other hidden characters may need CLEAN and SUBSTITUTE first.

Is there a way to prevent type mismatches in imported data?

Yes — set column data types explicitly in Power Query before loading, and validate with ISNUMBER after import.