Yes, the IF function works with text in Excel. You write =IF(A2="Yes","Approved","Rejected") and Excel compares the text in A2 to "Yes", returning one label if it matches and another if it does not. The key rules are that text values go inside double quotation marks, the comparison is not case-sensitive by default, and every comma separates an argument. Here is how to set it up correctly and what to do when the formula returns something unexpected.
What You'll Need
- A version of Excel that supports the IF function: Excel for Microsoft 365, Excel 2019 or newer, Excel for Mac, or a recent version of Excel for the web. Older versions such as Excel 2007 work too, but none of the newer functions like IFS or TEXTJOIN.
- A worksheet with text values already entered in a column, so there is something to test.
- Basic familiarity with cell references such as A2 and how to type a formula in the formula bar.
- Optionally, the exact text you want to match. Copy it from the source cell rather than retyping it, since a stray space or a different character breaks the match.
Step-by-Step
- Click a blank cell to the right of the text you want to test, for example B2 next to a name in A2. This is where the result appears.
- Type an equals sign and IF:
=IF(. Excel shows a tooltip listing the arguments: logical_test, value_if_true, value_if_false. - Enter the test, wrapping the text in double quotes. To check whether A2 equals "Open", type
A2="Open". The quotes tell Excel this is text rather than a cell reference or a function name. - Add a comma, then the value if true in quotes. For example
"Still pending". If you want a number or a blank result instead, leave the quotes off for a number, or use""(two double quotes with nothing between) for an empty cell. - Add a comma, then the value if false. For example
"Done". Close the bracket and press Enter. The full formula reads=IF(A2="Open","Still pending","Done"). - Copy the formula down. Drag the small square at the bottom-right corner of the cell, or double-click it to fill to the end of the adjacent data. Relative references adjust so A2 becomes A3, A4 and so on, while the quoted text stays fixed.
- Test the edge cases. Change a value in column A to different capitalisation, add a trailing space, and try a blank cell. Note what the formula returns, because these are the situations that cause most reported problems.
Labels such as the IF tooltip arguments can differ slightly in wording by version, device and region, but the syntax is the same everywhere.
Comparing text in different ways
Equality is only one option. These variations cover most real tasks:
- Not equal:
=IF(A2<>"Closed","Active","Archived")returns "Active" for anything that is not exactly "Closed". - Contains a word:
=IF(ISNUMBER(SEARCH("urgent",A2)),"Flag","OK"). SEARCH is case-insensitive and returns a position number when the text is found, so ISNUMBER converts that into TRUE or FALSE. Use FIND instead of SEARCH if you need a case-sensitive match. - Starts with:
=IF(LEFT(A2,3)="INV","Invoice","Other"). - Blank versus filled:
=IF(A2="","Missing","Entered"). A cell containing a space is not blank, which is why trailing spaces matter. - Case-sensitive exact match:
=IF(EXACT(A2,"ABC"),"Match","No match"). - Several categories: nest IFs or use IFS, for example
=IFS(A2="High",1,A2="Medium",2,A2="Low",3,TRUE,0). The final TRUE catches everything not already matched.
Common Mistakes
- Forgetting the quotation marks.
=IF(A2=Open,...)makes Excel look for a named range or function called Open and returns #NAME?. Text inside a formula always needs quotes. - Using curly or smart quotes. Text pasted from a word processor or website can carry typographic quotes (“ ”), which Excel does not treat as string delimiters in a formula. Retype them with the straight quote key.
- Hidden spaces. "Open " is not the same as "Open". Clean imported data with TRIM, or wrap the test as
TRIM(A2)="Open". - Assuming matches are case-sensitive. By default they are not: "OPEN", "open" and "Open" all match "Open". That is convenient until two values that should be distinct get merged. Use EXACT when case must count.
- Putting labels in quotes but forgetting commas. Missing or extra commas produce a "too many arguments" or "not enough arguments" error, not a wrong result you can spot.
- Comparing numbers stored as text. If A2 holds "100" as text (often after a CSV import) and you test
A2>50, the comparison goes wrong. Convert with VALUE or multiply by 1. - Hard-coding text instead of referencing a list. Typing the same label in dozens of formulas means editing every formula when the label changes. Put the lookup text in its own cell and reference it, or use a lookup function.
Tips
- Press F2 (or click the formula bar) to edit an existing formula; retyping from scratch is where quote mistakes creep in.
- Use the Formula Bar's argument tooltips, or the Insert Function dialog, to see which argument you are currently filling in.
- For a partial match on a long list, SEARCH with ISNUMBER is more reliable than trying to nest many IFs with LEFT and RIGHT.
- Keep return values short and consistent in case, since they are often used later for filtering or pivot tables.
- If you build a long nested IF, press Alt+Enter while editing to add line breaks and make each branch readable.
- Return
""rather than a hyphen for empty results if the column will be summed or counted later. - Where a text result will be joined into a sentence, remember it returns exactly what you typed, including capitalisation.
Troubleshooting
If the formula looks fine but returns the wrong result, work through these checks in order:
- Check the returned value against the source cell character by character. Select the source cell, look in the formula bar, and compare against your quoted text. Trailing spaces are the most common culprit.
- Test the comparison on its own. In a spare cell, type
=A2="Open". If it returns FALSE while the wording looks identical, the text does not match exactly. - Check for non-printing characters. Imported data sometimes contains line breaks or tabs.
=CODE(MID(A2,1,1))or CLEAN can reveal and remove them. - Verify the cell is text, not a number. A left-aligned entry is usually text; a right-aligned one is usually a number. ISTEXT tells you for certain.
- Look for #NAME? errors. These almost always mean a missing quotation mark around text, or a misspelled function name.
- Check Reference rules when copying. If the quoted text was entered without dollar signs and copied sideways, it may shift. Use absolute references such as
"Open"placed in$E$1if needed. - Recalculate. If nothing seems to update, set calculation to automatic in the Formulas options, or press F9 to force a recalculation.
Frequently Asked Questions
Is the IF function case-sensitive with text?
No, not by default. "Yes", "yes" and "YES" all match the text "Yes". Use the EXACT function inside IF when capitalisation must matter.
Why does my IF formula return #NAME?
Almost always because text was entered without quotation marks, so Excel treats it as a name it cannot find. Wrap every literal piece of text in straight double quotes.
Can I check whether a cell contains a word rather than matching it exactly?
Yes. Use =IF(ISNUMBER(SEARCH("word",A2)),"Yes","No"). SEARCH is not case-sensitive; swap in FIND for a case-sensitive check.
How do I return a blank cell when the test is false?
Use two quotation marks with nothing between them: =IF(A2="Open","Pending",""). Do not use a space, since that produces text of one character and can break later counts.
How do I test more than two or three possible text values?
Use IFS in current versions, which takes pairs of test and result followed by a final fallback. In older versions you can nest IFs, though each level adds a bracket pair that is easy to misplace.
Why does my text result look right but sort or filter oddly?
The formula probably returns a value that differs from what you see, such as a trailing space in the return string or inconsistent capitalisation across rows. Keep return values identical in format so sorting groups them properly.