If Cell Contains Text — With Examples (SEARCH, FIND, COUNTIF Wildcards)
Learn the Excel formula for if a cell contains specific text: ISNUMBER with SEARCH, FIND for case, and COUNTIF wildcards.
Read Guide →You have a list of exam scores and you need a column that decides: 90 and above is an A, 80 and above is a B, and below 60 is an F. Or a list of sales and you need a Yes or No: over $1,000, Yes, otherwise No. That is what IF does — it tests one condition and returns one value when the test is true and another when it is false. The formula has three parts, =IF(logical_test, value_if_true, value_if_false), and everything else in this guide is that pattern repeated: two conditions with AND and OR, several levels with a nested IF or IFS, and the two surprises — FALSE and 0 — that catch everyone once. Every example runs on a table in this article, so you can check each answer yourself.
Quick takeaway: one test, two answers.
=IF(logical_test, value_if_true, value_if_false) — true gives the first value, false gives the second.AND means all conditions must be true. OR means one is enough. NOT reverses a test.IFS (Excel 2019 and later)."Pass". Numbers without quotes: 1000.FALSE, not 0.
=IF(logical_test, value_if_true, value_if_false)
| Part | What it does |
|---|---|
logical_test | The condition Excel checks — a comparison like A2>=90, or a function like AND(...) |
value_if_true | The value returned when the test is TRUE — text, a number, or another formula |
value_if_false | The value returned when the test is FALSE — text, a number, or another formula |
The third part is technically optional, but leaving it out is how the FALSE surprise happens — the section near the end covers it. Text goes in double quotes, numbers do not: =IF(A2>=90, "A", "F") works, and =IF(C2>1000, C2-1000, 0) works.
Three small tables, one per idea. Every result below was checked against them.
Table 1 — exam scores, for the grades sections:
| Student | Score |
|---|---|
| Aisha | 92 |
| Ben | 78 |
| Carla | 65 |
| Dan | 88 |
| Eva | 54 |
| Finn | 71 |
| Grace | 83 |
| Hugo | 47 |
| Ivy | 96 |
| Jack | 59 |
Table 2 — two subjects, for the AND/OR sections:
| Student | Math | English |
|---|---|---|
| John | 55 | 65 |
| Mike | 48 | 70 |
| Sara | 72 | 58 |
| Omar | 45 | 59 |
| Lina | 80 | 85 |
Table 3 — the sales table from the COUNTIF and SUMIF articles, for the Yes/No section: the same ten orders (Alex, Priya, Jordan, Sam, Taylor — $1,200, $850, $2,400, $450, $1,750, $600, $900, $1,100, $300, $1,500). Total sales $11,050.
The simplest IF. One test, two answers.
| Goal | Formula | Result |
|---|---|---|
| Score 60 or above passes | =IF(A2>=60, "Pass", "Fail") | Aisha Pass, Eva Fail, Hugo Fail, Jack Fail |
| Sale over $1,000 gets a Yes | =IF(C2>1000, "Yes", "No") | 5 Yes, 5 No |
| Two cells equal? | =IF(A2=B2, "Yes", "No") | “Yes” when they match, “No” when they do not |
The sales question gives 5 Yes and 5 No: $1,200, $2,400, $1,750, $1,100 and $1,500 are over $1,000. And the third row is the answer to “if x = y”: put the comparison itself in the test — =IF(A2=B2, "Yes", "No") — and Excel returns Yes when the two cells hold the same value.
One IF gives two answers. For five grades, put an IF inside the false part of the one before it. Excel checks each condition in turn until one is true.
=IF(A2>=90, "A", IF(A2>=80, "B", IF(A2>=70, "C", IF(A2>=60, "D", "F"))))
| Score | Grade | Why |
|---|---|---|
| 92 | A | 92 is 90 or above |
| 78 | C | 78 is below 80, but 70 or above |
| 65 | D | 65 is below 70, but 60 or above |
| 88 | B | 88 is 80 or above |
| 54 | F | 54 is below 60 |
| 71 | C | 71 is 70 or above |
| 83 | B | 83 is 80 or above |
| 47 | F | 47 is below 60 |
| 96 | A | 96 is 90 or above |
| 59 | F | 59 is below 60 — one point short of a D |
Grade counts: A = 2, B = 2, C = 2, D = 1, F = 3 — ten students, all accounted for. Notice the order matters: the test must go from the highest boundary down. If you tested >=60 first, every score of 60 or above would return “D” and the higher grades would never be reached. And notice the trap in the last row: 59 is one point short of a D, and the formula does not care — a boundary is a boundary.
IFS does the same job without nesting. Each condition gets its own result, in pairs, and the last pair is the catch-all — TRUE with the final result, so that anything left over still gets an answer.
=IFS(A2>=90, "A", A2>=80, "B", A2>=70, "C", A2>=60, "D", TRUE, "F")
| Nested IF | IFS | |
|---|---|---|
| Same result? | Yes — identical grades for all ten scores | Yes — identical grades for all ten scores |
| Needs | Any Excel version | Excel 2019 and later |
| Reading it | Four closing brackets at the end | Flat pairs, no nesting |
| If no condition matches | The last value (“F”) is returned | #N/A — unless the last pair is TRUE |
The rule of thumb: three levels is fine as a nested IF; five levels means use IFS. And never leave the final TRUE out of an IFS — without it, a score that matches nothing returns #N/A instead of a grade.
When one condition is not enough, put AND or OR in the test slot. AND returns TRUE only when every condition inside it is TRUE. OR returns TRUE when at least one condition is TRUE. Each accepts up to 255 conditions.
Pass needs Math over 50 and English over 60:
=IF(AND(B2>50, C2>60), "Pass", "Fail")
Pass needs Math over 50 or English over 60:
=IF(OR(B2>50, C2>60), "Pass", "Fail")
| Student | Math | English | AND (both) | OR (either) |
|---|---|---|---|---|
| John | 55 | 65 | Pass | Pass |
| Mike | 48 | 70 | Fail | Pass |
| Sara | 72 | 58 | Fail | Pass |
| Omar | 45 | 59 | Fail | Fail |
| Lina | 80 | 85 | Pass | Pass |
AND passes 2 students (John and Lina). OR passes 4 (everyone except Omar). Mike is the row that shows the difference: his English is 70, so OR passes him, but his Math is 48, so AND fails him. Sara is the mirror image: her Math is 72, so OR passes her, but her English is 58, so AND fails her.
NOT reverses a test: =IF(NOT(A2>50), "Below 50", "50 or above") returns “Below 50” when the score is 50 or less. And the two can combine for a real-world rule — for example, a discount for East orders over $1,000, or for any order over $2,000:
=IF(OR(AND(B2="East", C2>1000), C2>2000), "Discount", "No discount")
On the sales table that gives a discount to 2 orders: the East orders are rows 2 ($1,200), 4 ($2,400), 7 ($600) and 8 ($900), and of those only rows 2 and 4 are over $1,000. The fallback rule — any order over $2,000 — catches row 4 only, which is already counted. So the discount rows are 2 and 4. The AND inside the OR does the precise work, and the OR adds the fallback rule.
IF does not have to return text. It can return a number, or another formula’s result.
=IF(C2>1000, C2-1000, 0)
| Sale | Amount over $1,000 |
|---|---|
| $1,200 | $200 |
| $850 | $0 |
| $2,400 | $1,400 |
| $450 | $0 |
| $1,750 | $750 |
| $600 | $0 |
| $900 | $0 |
| $1,100 | $100 |
| $300 | $0 |
| $1,500 | $500 |
Total over $1,000: $2,950. The 0 in the third part is doing real work here: without it, the rows at or below $1,000 would return FALSE, and adding the column would break. This is the answer to “if 0”: when you want a number back, always give IF a number for the false case — usually 0.
The two surprises, and they are both the same mistake: a missing third part.
| Symptom | What happened | Fix |
|---|---|---|
| IF returns FALSE | The third part was left out: =IF(A2>=60, "Pass") has no value for a fail, so Excel returns FALSE | Give the third part: =IF(A2>=60, "Pass", "Fail") |
| IF returns 0 | The false part returns a number, or the test compares a blank cell — a blank cell is 0 to Excel | Give the false part explicitly: =IF(A2="", "", A2*2) returns a blank for a blank cell instead of 0 |
| IF returns #N/A | An IFS with no matching condition and no final TRUE pair | End every IFS with TRUE, "your default" |
| IF returns #VALUE! | The test compares text with a number, e.g. A2>50 when A2 holds “abc” | Check the cell holds a number first |
The blank-cell rule deserves its own line, because it connects to another article: a blank cell is 0 to Excel, so =IF(A2="", "", A2*2) is the pattern that returns a blank instead of 0 — the full guide is the return blank instead of zero article.
| Mistake | What happens | Fix |
|---|---|---|
| You tested the lowest boundary first | Every score of 60 or above returns “D” and the higher grades are never reached | Test from the highest boundary down: 90, then 80, then 70, then 60 |
| You forgot a closing bracket | Excel shows an error or adds a bracket in the wrong place | Count the IFs: four IFs need four closing brackets at the end |
| You quoted a number | =IF(A2>="90", "A", "F") compares text with a number and misbehaves | Numbers without quotes: A2>=90 |
| You used AND when you meant OR | Only 2 students pass instead of 4 | AND means all must be true; OR means one is enough |
| You nested five levels deep | The formula works but nobody can read it, including you next month | Use IFS — flat pairs, one condition per line of logic |
| You left the third part out | A false test returns FALSE | Always give value_if_false, even if it is just "" or 0 |
What is the IF formula in Excel? =IF(logical_test, value_if_true, value_if_false). For example, =IF(A2>=60, "Pass", "Fail") returns Pass when the score is 60 or above, and Fail otherwise.
How do I write an IF formula with two conditions in Excel? Put AND or OR in the test: =IF(AND(B2>50, C2>60), "Pass", "Fail") needs both, =IF(OR(B2>50, C2>60), "Pass", "Fail") needs either one.
How do I write multiple IF statements in Excel? Nest them: =IF(A2>=90, "A", IF(A2>=80, "B", IF(A2>=70, "C", IF(A2>=60, "D", "F")))). Or use IFS in Excel 2019 and later: =IFS(A2>=90, "A", A2>=80, "B", A2>=70, "C", A2>=60, "D", TRUE, "F").
What is the difference between IF and IFS? IF handles one test with two answers, and nesting gives more levels. IFS handles several tests in flat pairs, is easier to read, and needs a final TRUE pair or it returns #N/A when nothing matches.
How do I make an IF formula return Yes or No in Excel? Put the words in the two result slots: =IF(C2>1000, "Yes", "No"). On the sales table that gives 5 Yes and 5 No.
Why does my IF formula return FALSE? The third part was left out. =IF(A2>=60, "Pass") has no value for a fail, so Excel returns FALSE. Add it: =IF(A2>=60, "Pass", "Fail").
How many IFs can I nest in Excel? Excel allows nesting up to 64 levels. In practice, stop at three or four and switch to IFS — a 64-level nested IF is unreadable.
That is the IF formula in Excel: one test, two answers — =IF(logical_test, value_if_true, value_if_false) — with AND when all conditions must be true, OR when one is enough, and a nested IF or IFS when there are several levels. On the tables in this guide, that one pattern answers every question: ten scores become two As, two Bs, two Cs, one D and three Fs; two subjects become two passes under AND and four under OR; ten sales become five Yes and five No; and the amount over $1,000 adds up to $2,950. Remember the two things that catch everyone once: test from the highest boundary down, or the lower grades swallow the higher ones, and always give the third part — a false test with nowhere to go returns FALSE, not 0. From here, the next functions worth learning are the ones this one sits next to — the COUNTIF formula for counting instead of deciding, the SUMIF formula for adding instead of deciding, and the full learning order for the whole site is on the Excel Formulas hub and the Logical & Conditional category page.
Learn the Excel formula for if a cell contains specific text: ISNUMBER with SEARCH, FIND for case, and COUNTIF wildcards.
Read Guide →Learn how to highlight an entire row in Excel based on a cell value: the locked-column formula, text, numbers, dates and mistakes.
Read Guide →Learn the SUMIF formula in Excel: sum values by text, number, date or wildcard, with worked examples — plus SUMIFS for two...
Read Guide →