Sub topic 3
Fixing #VALUE!: wrong type of value in a formula
This chapter assumes you can enter and edit formulas, use cell references and ranges, and tell numbers from text in a cell. Excel returns #VALUE! when a formula contains a value of the wrong type, such as text where a number is required. The formula is syntactically valid, but Excel cannot compute it with the values it received.
What causes #VALUE!
Most #VALUE! errors come from one of these causes:
- An arithmetic operator (
+,-,*,/) is applied to a cell that holds text, such as "n/a" or "N/A". - A cell that looks empty contains a space or an empty string returned by another formula.
- A number is stored as text, sometimes with leading or trailing spaces.
- A function argument has the wrong type, for example a range where a single value is expected.
The error appears in the cell holding the formula, not in the cell with the bad data. To find the real cause, look at each cell the formula refers to.
Worked example: text in an addition
Suppose A2 holds 10 and B2 holds the text n/a. This formula fails:
=A2+B2The + operator needs two numbers, and n/a is not a number, so the result is #VALUE!.
You have two ways to fix it. If the text is a real placeholder and you want to treat it as nothing, use a function that skips text in cell references:
=SUM(A2,B2)SUM ignores text that it finds in cell references, so this returns 10. Use this only when ignoring the text is the right business decision. If "n/a" means a value is missing, a total of 10 may hide that fact.
If instead the cell should contain a number, correct the data in B2.
Worked example: numbers stored as text
Data imported from other systems often contains numbers that Excel treats as text. A common sign is a number aligned to the left of the cell, or a small green triangle in the cell's corner. Extra spaces cause the same trouble, because " 25" is not the number 25.
This formula removes leading and trailing spaces and converts the result into a real number:
=VALUE(TRIM(A2))TRIM strips the spaces. VALUE converts the cleaned text to a number. You can then use the result in calculations, for example =VALUE(TRIM(A2))*B2.
Spaces that look like normal spaces can also be non-breaking spaces (character code 160), which TRIM does not remove. If TRIM does not fix the problem, replace them first with SUBSTITUTE(A2,CHAR(160),"").
Mismatched argument types
Some functions require a particular kind of argument. For example, a date function given text that is not a valid date returns #VALUE!. The same happens when a function expects one value and receives a multi-cell range in a context where Excel cannot work with it. To diagnose this, select the function in the formula bar and read the argument tooltip, then check what each argument actually contains.
Common mistakes
- Wrapping the formula in IFERROR straight away. This hides the error but leaves the bad data in place. Find the cause first.
- Assuming a blank-looking cell is empty. Use
=LEN(B2)to check. A result above 0 means the cell holds something, such as a space. - Retyping the number without changing the cell format. If the cell is formatted as Text, a typed number can remain text. Change the format to General or Number, then re-enter the value.
Exercise
A2 contains 40 and B2 contains the text "pending". The formula =A2*B2 returns #VALUE!. Give one formula that returns 40 instead of an error, and say when using it would be a poor choice.
Show answer
Use =SUM(A2,B2), which returns 40 because SUM ignores text in cell references. (=A2 alone also works.) It is a poor choice when "pending" means the value is still missing, because the result 40 would look like a complete answer. Note that SUM adds the values rather than multiplying them, so it only matches the original intent if you want a total. To keep multiplication, use =IF(ISNUMBER(B2),A2*B2,"") instead.
Exercise
A cell holds the text " 125 " with a space on each side. Write a formula that turns it into a number you can use in calculations.
Show answer
=VALUE(TRIM(A2)), with A2 as the cell holding the text. TRIM removes the spaces and VALUE converts the remaining text to the number 125.