Last updated July 2026. The IF function tests a condition and returns one value when it is true and another when it is false. The syntax is =IF(logical_test, value_if_true, value_if_false). For example, =IF(B2>0, "Credit", "Debit") reads the amount in B2 and writes "Credit" when it is positive and "Debit" when it is not. That single pattern, a test plus two outcomes, is the whole function, and everything else is combining it with other functions or nesting it.
On a converted PDF, IF is how you turn raw numbers into decisions: flag rows over a limit, label credits and debits, mark blanks as missing, or bucket amounts into categories. It reads what is there and writes a plain-language result next to it, which is why it is one of the first formulas most people learn and one they keep using every day.
How do I use the IF function in Excel?
Type =IF( then give it three parts separated by commas: the test, the result if the test is true, and the result if it is false. Put text results in double quotes and leave numbers bare. So =IF(C2>=1000, "Review", "OK") writes "Review" for any amount of 1000 or more and "OK" for the rest. Press Enter and fill the formula down the column; the reference C2 shifts to C3, C4, and so on, testing each row against its own value.
The comparison in the test can use any of the operators: equals (=), not equal (<>), greater than (>), less than (<), or the "or equal to" versions (>=, <=). You can also leave a result empty with "" to write nothing, which is handy when you only want a label in the rows that matter: =IF(D2="", "Missing", "") marks blank cells and leaves the rest clear.
How do I use IF with two conditions?
Wrap AND or OR around the test. Use AND when both conditions must be true and OR when either is enough. To flag a row only when the amount is over 500 and the status is open, write =IF(AND(C2>500, D2="Open"), "Follow up", ""). To flag when either the amount is negative or the date is missing, write =IF(OR(C2<0, E2=""), "Check", ""). AND and OR each take up to 255 conditions, so you can stack as many tests as a rule needs.
Keep the logic readable by grouping. AND and OR each return a single TRUE or FALSE, and IF just acts on that result, so you can combine them, like =IF(AND(C2>500, OR(D2="Open", D2="Pending")), "Follow up", ""). Read it from the inside out: the OR resolves first, the AND folds in the amount test, and IF turns the final TRUE or FALSE into your label.
How do I write a nested IF for multiple outcomes?
Put another IF in the value_if_false slot to add more than two outcomes. To grade amounts into three bands: =IF(C2>=1000, "High", IF(C2>=500, "Medium", "Low")). Excel checks the first test, and if it fails, moves to the second IF, and so on. Order the tests from highest to lowest (or narrowest to widest) so each one only catches what the earlier tests let through.
Nested IFs work but get hard to read past three or four levels, and a single misplaced parenthesis breaks the whole thing. Excel allows up to 64 nested IFs, but you rarely want more than a few. When you find yourself stacking many conditions, the IFS function below is cleaner, and for looking up a result from a table, a VLOOKUP or a lookup table beats a long nested IF every time.
| Need | Formula |
|---|---|
| Two outcomes | =IF(C2>0, "Credit", "Debit") |
| Both conditions true | =IF(AND(C2>500, D2="Open"), "Follow up", "") |
| Either condition true | =IF(OR(C2<0, E2=""), "Check", "") |
| Three or more bands (nested) | =IF(C2>=1000,"High",IF(C2>=500,"Medium","Low")) |
| Many bands (cleaner) | =IFS(C2>=1000,"High",C2>=500,"Medium",TRUE,"Low") |
| Cell contains text | =IF(ISNUMBER(SEARCH("inv",A2)), "Invoice", "") |
What is IFS and when should I use it?
IFS tests several conditions in order and returns the result for the first one that is true, without nesting. The syntax is =IFS(test1, result1, test2, result2, ...). The three-band grade becomes =IFS(C2>=1000, "High", C2>=500, "Medium", TRUE, "Low"). The final TRUE acts as the catch-all, standing in for the last "otherwise" value. IFS is available in Excel 2019, 2021, and Microsoft 365; older versions still need nested IFs.
Use IFS when you have three or more conditions and no need to nest anything inside the results, because it reads left to right and is far easier to audit. Stick with IF when you have a simple two-way choice or when you need to nest other logic inside a branch. One gotcha: if none of the IFS conditions is true and you left out the TRUE catch-all, it returns an #N/A error, so always end with TRUE and a default.
How do I use IF when a cell contains specific text?
Combine IF with ISNUMBER and SEARCH, because IF alone cannot check for a word inside a longer string. Use =IF(ISNUMBER(SEARCH("invoice", A2)), "Invoice", "Other"). SEARCH looks for "invoice" anywhere in A2 and returns its position as a number if found or an error if not; ISNUMBER turns that into TRUE or FALSE, and IF writes the label. SEARCH ignores case, so it matches "Invoice" and "INVOICE" too; swap in FIND if you need a case-sensitive match.
This is a workhorse on converted documents, where a description column holds mixed text and you want to categorize rows by a keyword. When the source is an invoice, a tool that pulls each line item into a spreadsheet automatically hands you clean columns to test, so your IF formulas run against tidy data instead of one messy string.
How do I hide errors with IFERROR?
Wrap a formula in IFERROR to replace any error with a value you choose. The syntax is =IFERROR(your_formula, value_if_error). A lookup that misses returns #N/A; =IFERROR(VLOOKUP(A2, table, 2, FALSE), "Not found") swaps that ugly error for a plain label. It is the polite companion to IF: IF decides what to show when a test passes or fails, while IFERROR decides what to show when a formula breaks.
Use it on converted data where some rows are incomplete and errors are expected, such as a division that hits a blank cell (=IFERROR(C2/D2, 0) returns 0 instead of #DIV/0!). One warning: IFERROR hides every error, including ones that signal a real problem, so do not blanket a whole sheet with it. Clean the data first, then use IFERROR only where a missing value is genuinely acceptable.
Why does my IF formula return the wrong result?
The usual culprit is a number stored as text. IF compares "150" as text differently from the number 150, so =IF(C2>100, "High", "Low") can return "Low" for a value that is clearly above 100. The cell looks like a number but is left-aligned and tagged with a green triangle. Fix it by converting the text to numbers first, then the comparison behaves. Stray spaces cause the same trouble in text tests, where "Open " with a trailing space fails to equal "Open".
Two more to watch. Forgetting the quotes around text results throws a #NAME? error, since Excel reads bare words as range names. And a nested IF that returns the wrong band almost always has its tests in the wrong order, so a value that should be "High" gets caught by an earlier, looser test. Read the logic top to bottom and make sure each test is stricter than the one below it.
IF is one tool in a full converted-file cleanup. Once your labels and flags are in place, work through the steps for cleaning up data after a PDF conversion, and begin with an accurate PDF to Excel conversion so the values your formulas test are right to start with.