The basic pattern: =IF(A1="Yes","Approved","Pending"). That's case-insensitive โ "yes", "YES", and "Yes" all match. Need exact case matching? Use =IF(EXACT(A1,"YES"),"Approved","Pending"). Looking for a word inside a longer string? Wrap SEARCH in ISNUMBER: =IF(ISNUMBER(SEARCH("error",A1)),"Issue","OK"). The biggest mistake people make? Forgetting quotes around text values. Without quotes, Excel thinks you typed a named range and throws #NAME?.
You have a column of statuses. "Approved", "Pending", "Rejected". You want column B to show a clean message based on what's in column A. Maybe "Send invoice" when approved, "Wait" when pending, "Refund" when rejected. That's the if function excel doing its job with text โ and once you nail the syntax, it powers half of every real spreadsheet you'll ever build.
Here's the thing about text comparisons: Excel handles them differently than numbers. Quotes matter. Case usually doesn't, except when it does. Partial matches need a helper function. And the moment you forget a single quotation mark, the whole formula collapses into #NAME? or returns the wrong branch silently. This guide walks through every pattern that comes up in real work โ status detection, category mapping, name matching, document classification โ with the exact syntax for each.
Three arguments, two of them text. The logical test compares A1 to a literal string. Both branches return strings. Quotes everywhere except around the cell reference. That's the whole template.
Real example: =IF(A1="Yes","Approved","Pending"). If A1 contains Yes, the formula returns Approved. Anything else โ No, Maybe, blank, a number, a typo โ returns Pending. Case-insensitive by default. "yes", "YES", and "yEs" all match. That's usually what you want for human-entered data where casing is inconsistent.
What if you need the opposite? What if "YES" should match but "yes" should not? That's where EXACT comes in, which we cover in the next section.
For now, lock in the basic pattern: cell reference (no quotes), comparison value (quotes), true result (quotes), false result (quotes). Memorize that rhythm and 80% of your IF-with-text problems disappear before they start. The other 20% comes from forgetting that Excel treats text "5" and the number 5 as different beasts. We'll get to that too. First, the case-sensitivity question โ because it's the one that most often turns a working formula into a quietly broken one.
Default Excel doesn't care about case. =IF(A1="Yes","OK","No") returns OK whether A1 holds "yes", "Yes", "YES", or even "yEs". For most messy real-world data โ typed by humans, copied from emails, imported from web forms โ that's exactly the behavior you want. Forcing case sensitivity on inconsistent human input creates more bugs than it fixes.
But some data is case-meaningful. Product SKUs like "AB-100" versus "ab-100" might be different items. License plates. Passwords. Two-letter country codes where "US" and "us" mean different things in your downstream system. For those, default IF lies to you โ it returns matches that shouldn't match. That's where EXACT earns its place in your toolbox.
EXACT compares two text strings character by character, including case. It returns TRUE only if every byte matches. Wrap it inside IF: =IF(EXACT(A1,"YES"),"Approved","Reject"). Now "YES" returns Approved but "yes" returns Reject. Same logic works for any case-sensitive comparison: =IF(EXACT(B2,"Admin"),"Grant","Deny") only grants access when the role is capitalized exactly as "Admin".
Worth knowing: EXACT also catches trailing spaces and invisible characters that default = ignores in some edge cases. If you're getting false matches on what look like identical cells, run EXACT to confirm. If EXACT returns FALSE but the cells look the same, you have hidden whitespace or a non-breaking space lurking inside. Wrap with TRIM to clean it: =IF(EXACT(TRIM(A1),"YES"),"OK","No").
Here's a bug that's eaten hours of analyst time: a status report where "Closed" should mean something different from "closed". Maybe "Closed" is final-closed by a manager. "closed" is auto-closed by a system overnight. They look identical in a sorted column. A default IF treats them as the same. Three weeks later your report shows wrong numbers.
Nobody can figure out why. Use EXACT from day one if case carries meaning. Document the choice in a comment cell or named-range note. Save your future self the debug session.
Setup: Column A has order statuses. You want column B to show next action.
Formula: =IF(A2="Approved","Ship today",IF(A2="Pending","Wait for review","Refund customer"))
Three-way logic nested. A2 is checked first โ if Approved, return Ship today. If not, the next IF checks for Pending. Anything that fails both falls to Refund. Order matters: put the most common case first for readability, and put the catch-all in the deepest false branch.
Setup: Column A has product types. You want column B to map them to one of three departments.
Formula: =IF(OR(A2="Laptop",A2="Desktop",A2="Tablet"),"Electronics",IF(OR(A2="Shirt",A2="Pants"),"Apparel","Other"))
OR groups multiple text values into one logical branch. Faster to read than five nested IFs. For more than four or five categories per group, switch to SWITCH or IFS โ nesting gets unwieldy past three levels.
Setup: Column A has full names. Flag any row where the last name is Smith.
Formula: =IF(ISNUMBER(SEARCH("Smith",A2)),"Smith family","Other")
SEARCH is case-insensitive and returns the position of the match (a number) or #VALUE! if no match. ISNUMBER wraps it to convert that into TRUE/FALSE for IF. Use FIND instead of SEARCH if you need case-sensitive name matching.
Default IF only matches whole strings. =IF(A1="error","Bug","OK") returns Bug only when A1 contains literally the word error and nothing else. A cell with "connection error" or "error code 500" returns OK โ because the comparison is exact. To check whether a word appears anywhere inside a longer string, you need a helper function.
The standard pattern: =IF(ISNUMBER(SEARCH("error",A1)),"Issue","OK"). SEARCH returns the character position where "error" starts inside A1, or a #VALUE! error if it's not there. ISNUMBER converts a position (a real number) to TRUE and an error to FALSE. Wrap that in IF and you have a clean substring detector. Add as many as you need to scan multiple keywords. Build a log parser. Build a complaint classifier. The pattern scales.
SEARCH is case-insensitive โ "Error", "ERROR", and "error" all match. FIND is case-sensitive โ only the exact case matches. Same syntax, different behavior. Use SEARCH 90% of the time. Reach for FIND only when case carries meaning, like distinguishing "IT" (the department) from "it" (the pronoun) in survey responses.
Both functions accept a third argument: where in the string to start looking. =SEARCH("x",A1,5) starts searching from character 5 onward โ useful when you want to find the second occurrence of something, or skip a prefix. Pair with FIND in nested fashion: =FIND("@",A1,FIND("@",A1)+1) finds the SECOND "@" sign in an email-looking string by starting the second FIND one position after the first hit.
Another way to detect a substring: =IF(COUNTIF(A1,"*error*"),"Issue","OK"). COUNTIF supports wildcards โ * for any sequence of characters, ? for exactly one character. Wrapping in IF works because COUNTIF returns 1 (truthy) when the pattern matches and 0 (falsy) when it doesn't. No ISNUMBER wrapper needed. Slightly more concise than the SEARCH version, and easier to read once you know the trick.
The wildcard approach also handles patterns SEARCH can't. =IF(COUNTIF(A1,"???-???-????"),"Phone","Other") matches anything that looks like a US phone number (3 chars, dash, 3 chars, dash, 4 chars). Building format-recognition logic without regular expressions becomes possible. Excel doesn't have native regex, so COUNTIF wildcards are often your best fallback. For more pattern work see the excel search function guide.
What if you want to match against several text values at once? Approved or Pending should both count as "in progress". Three or four product categories should all map to "Electronics". The naรฏve approach is nested IFs โ readable up to two or three levels, ugly beyond that. Better: use OR to group values inside the logical test.
Standard pattern: =IF(OR(A1="A",A1="B",A1="C"),"Match","No"). OR accepts up to 255 conditions. The formula returns Match if any one of them is true. Order doesn't matter to OR โ it short-circuits on the first TRUE so you get a tiny speed boost by putting the most-likely match first, but for most data sets it doesn't show up in benchmarks.
SWITCH (Excel 2019 and Microsoft 365) handles many-to-one text mapping more elegantly than nested IFs. Syntax: =SWITCH(A1,"A","Group 1","B","Group 1","C","Group 2","Other"). Read it as pairs: "if A1 equals A, return Group 1; if A1 equals B, return Group 1; ...; if nothing matches, return Other". The last argument is the default. Cleaner than five nested IFs. Faster to type. Easier to maintain.
Caveat: SWITCH does exact case-sensitivity unlike default IF. "A" matches but "a" doesn't. To force case-insensitive, wrap with UPPER: =SWITCH(UPPER(A1),"A","Group 1","B","Group 1","Other"). Or use IFS with explicit comparisons: =IFS(OR(A1="A",A1="a"),"Group 1",OR(A1="B",A1="b"),"Group 1",TRUE,"Other"). For complex multi-condition logic see excel if contains patterns and the related excel if statement guide.
For more than ten text values, stop writing formulas and build a lookup table. Put your text-to-result mappings in two columns on a separate sheet. Use VLOOKUP or XLOOKUP to do the matching. Easier to maintain. Adding a new mapping is a single row insert, not a formula edit across 5,000 cells.
Once you cross 8 or 10 distinct text values, the lookup table wins on every dimension: readability, speed, maintenance. Bonus: business users can edit the mapping table without touching formulas, which means fewer panicked support requests.
Three errors eat 90% of IF-with-text debugging time. Once you recognize the pattern of each, fixing them takes seconds. Without that pattern recognition, you'll stare at a formula for ten minutes wondering why it returns the wrong branch.
Wrong: =IF(A1=Yes,"OK","No"). Right: =IF(A1="Yes","OK","No"). Without quotes around Yes, Excel thinks you're referencing a named range called Yes. If no such range exists, you get #NAME?. If one does exist (and someone named a cell Yes years ago and forgot), the formula returns whatever's in that cell โ silently giving wrong answers. Always quote text literals. Always.
Wrong: =IF(A1='Yes','OK','No'). Right: =IF(A1="Yes","OK","No"). Single quotes (apostrophes) don't mark strings in Excel โ they're used for sheet name escaping and as text-format indicators. Use straight double quotes for all text values. If you copy a formula from a webpage or Word doc, beware curly quotes (โ smart โ quotes) โ Excel doesn't recognize them as string delimiters either.
If A1 contains the number 5 (not the text "5"), then =IF(A1="5","OK","No") returns No, because Excel distinguishes between text "5" and the number 5. The fix is either drop the quotes when comparing numbers โ =IF(A1=5,"OK","No") โ or force conversion: =IF(TEXT(A1,"0")="5","OK","No"). Mixed-type columns where some entries are numbers and others are text (common in imported CSVs) need explicit handling either way.
IF gets dramatically more useful when you combine it with the text-extraction trio: LEFT (first N chars), RIGHT (last N chars), and MID (any slice). The pattern: extract a piece of text, then compare it in the IF logical test.
Examples that come up constantly: =IF(LEFT(A1,3)="ABC","Group 1","Other") checks if a code starts with ABC. =IF(RIGHT(A1,4)=".pdf","PDF file","Other") classifies file extensions. =IF(MID(A1,4,2)="US","US item","Intl") checks if characters 4-5 are "US" โ useful for SKUs encoding country in a fixed position. The pattern scales to any text slice.
One more combo worth memorizing: LEN inside IF for length checks. =IF(LEN(A1)=10,"Valid phone","Wrong length") flags any cell that isn't exactly 10 characters. Useful for ZIP code validation, phone number formatting, and ID-field sanity checks. For broader text formula patterns see the excel formulas guide and the dedicated if then excel walkthrough.
IF can return any data type โ text, number, formula result, blank, error. The branches don't have to match each other in type. =IF(A1="Yes",100,"Pending") returns the number 100 for matches and the text "Pending" otherwise. Excel doesn't object. But mixed-type return values cause subtle problems downstream: SUM ignores the text values, sort orders text and numbers separately, and pivot tables may treat the column as text and refuse to aggregate.
Best practice: pick a return type per column and stick to it. If the result will be summed or averaged, return numbers in both branches (use 0 for false). If it'll display as labels, return text in both. =IF(A1="Yes",1,0) creates a numeric flag โ easy to SUM, filter, and feed into other math. =IF(A1="Yes","Approved","Pending") creates a label column โ readable, sortable as text. Don't mix.
To return an empty cell instead of a placeholder string, use "" (two double quotes with nothing between). =IF(A1="Yes","Approved","") shows Approved or nothing. Worth noting: that empty string isn't truly blank.
ISBLANK still returns FALSE on the result because the cell contains a zero-length string. For downstream formulas that distinguish blank from empty string, this matters. excel if cell contains text covers the difference in depth โ short version: use ISBLANK to test, but expect IF-generated empties to fail that test.
You have a column of email subject lines from a customer service inbox. You want to auto-tag each one: urgent, billing, technical, general. Pure text comparisons can't do it โ subjects are free-form, never identical. SEARCH-based partial matching can.
The formula: =IF(ISNUMBER(SEARCH("urgent",A2)),"Urgent",IF(OR(ISNUMBER(SEARCH("refund",A2)),ISNUMBER(SEARCH("invoice",A2))),"Billing",IF(OR(ISNUMBER(SEARCH("error",A2)),ISNUMBER(SEARCH("crash",A2))),"Technical","General"))). Reads: first check for the word urgent โ that overrides everything. Then check for billing keywords. Then technical. Anything that matches none falls into General. Order matters because the first true branch wins. Always check the most specific or most critical category first.
For dozens of categories with dozens of keywords, build it as a lookup table. Each row is a keyword + a category. Use SUMPRODUCT with SEARCH across the keyword column to score matches. The IF-nested approach scales to maybe 5-7 categories before it becomes unreadable.
IF formulas are cheap. Even 100,000 rows of basic text comparisons recalculate in under a second on modern hardware. SEARCH and FIND inside IF cost slightly more โ they scan character by character โ but still fast. Where performance gets interesting: nested IFs more than 4 deep, or IFs that contain VLOOKUP inside both branches.
If your sheet feels sluggish during recalc, IF formulas are rarely the culprit. Look at VLOOKUPs across huge ranges, SUMPRODUCT with multiple arrays, or anything that references whole columns (A:A) instead of bounded ranges. Wrap an IF around an expensive lookup to short-circuit it: =IF(A2="","",VLOOKUP(A2,Table,2,FALSE)) skips VLOOKUP entirely when A2 is blank. Multiply across 50,000 rows. Real seconds saved.
Bottom line on Excel IF function with text: nail the basic syntax, know EXACT for case-sensitive matching, use ISNUMBER(SEARCH()) for partial matches, group multiple values with OR or switch to SWITCH/IFS for cleaner mapping. Always quote your text literals.
Master those five patterns and you've covered 95% of real-world text-based IF formulas. The remaining 5% โ array formulas, regex via custom functions, fuzzy matching โ needs add-ins or VBA. For everything else, the patterns in this guide cover the territory.
Write down in plain English what you're checking. Example: 'If status is Approved, mark as shipping; otherwise mark as waiting.' Clear test = clear formula.
Decide if 'Yes' and 'yes' should match. Yes = default IF with =. No = wrap with EXACT(). Human-entered data usually = case-insensitive.
Whole cell equality = default. Word inside a longer string = ISNUMBER(SEARCH()) or COUNTIF with wildcards. Pick before writing.
Wrap text values in straight double quotes. Cell references stay unquoted. This single rule prevents most #NAME? errors.
Before copying down, manually verify with one TRUE and one FALSE case. Saves hours of debugging on a 10,000-row sheet.
=IF(A1="Yes","Approved","Pending"). Excel compares A1 to the literal text "Yes" โ case-insensitive by default โ and returns Approved on match, Pending otherwise. The most common mistake: forgetting the quotes, which makes Excel think you typed a named range and throws #NAME?.=IF(A1="yes","OK","No") matches "yes", "YES", and "Yes" all the same. To force case sensitivity, use EXACT inside IF: =IF(EXACT(A1,"YES"),"OK","No"). EXACT only returns TRUE when every character including case is identical. Use it for product codes, IDs, and other case-meaningful data.=IF(ISNUMBER(SEARCH("error",A1)),"Issue","OK"). SEARCH returns a number when the word is found anywhere in A1, or #VALUE! when not. ISNUMBER converts that to TRUE/FALSE. Use SEARCH for case-insensitive matching, FIND for case-sensitive. Another option: =IF(COUNTIF(A1,"*error*"),"Issue","OK") using COUNTIF wildcards.=IF(OR(A1="A",A1="B",A1="C"),"Match","No"). OR accepts up to 255 conditions and returns TRUE if any one matches. For many-to-one mapping with cleaner syntax, use SWITCH (Excel 2019+): =SWITCH(A1,"A","Group 1","B","Group 1","Other"). Beyond 8 or 10 values, build a lookup table and use VLOOKUP or XLOOKUP instead.=IF(A1=Yes,"OK","No") fails because Excel reads Yes as a named range. The fix: =IF(A1="Yes","OK","No"). Also watch for curly quotes from Word โ copy a formula from a Word doc and Excel won't recognize the smart quotes as string delimiters. Always type formulas directly in Excel or paste them as plain text first.=IF(COUNTIF(A1,"*yes*"),"Match","No") uses * as a wildcard for any sequence of characters. COUNTIF returns 1 on match and 0 otherwise, which IF reads as TRUE/FALSE. This pattern handles substring matching, prefix matching, suffix matching, and rough pattern recognition like phone number formats.=IF(LEFT(A1,3)="ABC","Group 1","Other") checks the first 3 characters. =IF(RIGHT(A1,4)=".pdf","PDF","Other") checks the last 4. =IF(MID(A1,4,2)="US","US","Intl") grabs characters 4-5. Useful for SKUs, file extensions, fixed-format codes. The extracted piece is just text, so all standard IF text rules apply โ quote your comparison value.#VALUE! when not found โ wrap in ISNUMBER for clean TRUE/FALSE results inside IF.