In Excel, an IF formula checks whether a condition is true and returns one value if it is, or another value if it is false. For example, if a score is in A2, =IF(A2>=60,"Pass","Fail") displays Pass for a score of 60 or higher and Fail for a lower score.
What the IF function does
IF is a logical function: it lets a worksheet make a decision based on a test. That test might compare a number with a threshold, check whether two text entries match, or determine whether a cell is empty. IF does not change the original data; it returns a result in the cell containing the formula.
The function has three arguments, in this order:
- Logical test: the condition Excel evaluates, such as whether a value is greater than or equal to a target.
- Value if true: what the formula returns when the test is true. This can be text in quotation marks, a number, a cell reference, or another formula.
- Value if false: what it returns when the test is false. This argument is also required, even if the intended result is an empty-looking cell.
For example, the comparison A2>=60 is true when A2 contains 60, 75, or 100, and false when it contains 59. IF evaluates that comparison and chooses the matching result. Text results need straight double quotation marks in the formula; numbers and cell references do not.
A simple pass-or-fail example
Suppose column A contains test scores, with the first score in A2. To label scores of at least 60 as passing, enter this in B2:
With the score in A2, this formula returns Pass when A2 is 60 or higher and Fail otherwise: =IF(A2>=60,"Pass","Fail")
If A2 contains 72, the result is Pass. If A2 contains 45, the result is Fail. The comparison operator matters: >= means greater than or equal to, while > alone would make a score of exactly 60 fail. Other common comparison operators include < for less than, <= for less than or equal to, = for equal to, and <> for not equal to.
To apply the rule to more scores, copy or fill the formula down column B. Excel adjusts the relative reference from A2 to A3, A4, and so on. Check the first few results after filling to confirm that each row is using the score from the same row.
Returning numbers and calculating amounts
IF can return numbers as well as labels. This is useful for conditional fees, bonuses, discounts, or other worksheet calculations. Imagine that order totals are in B2 and a simple example policy awards a 5% discount on totals of at least $1,000. This is only an illustrative spreadsheet rule, not a recommendation about pricing.
With the order total in B2, this formula returns 5% of the total when it is at least 1,000, or zero otherwise. For B2 equal to 1,200, the result is 60; for B2 equal to 800, it is 0: =IF(B2>=1000,B2*5%,0)
Because the true result is a calculation, the formula multiplies the amount by 5%. You could format the result cell as Currency to display the result as money, but number formatting changes only how the result looks, not the underlying calculation. If the threshold or percentage may change, consider putting those values in separate cells and referring to them rather than typing them into every formula. That makes the rule easier to update and review.
Checking for blank cells
A common worksheet problem is that a formula displays zero or an unwanted message before a row has been filled in. IF can return an empty string when a key input is blank. An empty string is text with no visible characters; it makes the result cell look empty, but the cell still contains a formula.
Suppose A2 contains a unit price and B2 contains a quantity. With the price in A2 and quantity in B2, this formula leaves the result visually blank if A2 is empty; otherwise, it multiplies price by quantity. If A2 is 12 and B2 is 3, the result is 36: =IF(A2="","",A2*B2)
This version checks only A2. If A2 has a price but B2 is empty, Excel treats the blank quantity as zero in the multiplication, so the formula returns 0. If the result should stay blank until both inputs are present, test both cells instead.
With the price in A2 and quantity in B2, this version returns an empty string if either input is blank; when A2 is 12 and B2 is 3, it returns 36: =IF(OR(A2="",B2=""),"",A2*B2)
A formula that returns an empty string is not the same as a truly empty cell. For instance, counting functions and charts may treat formula results differently from cells that were never filled in. If later calculations depend on whether a cell is genuinely empty, keep that distinction in mind.
Using nested IF for several outcomes
When one condition is not enough, you can put another IF inside the first one. This is called a nested IF. Excel checks the first condition; if it is false, it evaluates the next IF, continuing until a condition is true or it reaches the final fallback result.
For a grading example, assume a score is in B2: 90 or above earns A, 80–89 earns B, 70–79 earns C, and anything below 70 is labeled Below C. With the score in B2, this formula returns B for a score of 84 and Below C for a score of 68: =IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C","Below C")))
The order of checks is important. The formula tests the highest threshold first, then moves downward. If it tested 70 or above first, a score of 95 would meet that condition and receive C before Excel ever checked for an A. For a clear and reliable nested IF:
- Write down the ranges and their intended labels before building the formula.
- Check thresholds from highest to lowest, or lowest to highest, without overlapping the logic.
- Use a final value for all cases that do not meet an earlier condition.
- Test boundary values such as 69, 70, 79, 80, 89, and 90, not just typical scores.
For a long list of categories or changing rules, a lookup table may be easier to maintain than a deeply nested formula. Nested IF is handy for a few outcomes; it becomes harder to inspect as the number of branches grows.
Combining conditions with AND and OR
Use AND when every condition must be true, and OR when at least one condition must be true. These functions can go inside IF’s logical test. That keeps the result easy to interpret: first Excel evaluates the combined test, then IF selects the true or false result.
Suppose B2 contains a score and C2 contains a completion status. A person qualifies only with a score of at least 70 and the exact status Complete. With the score in B2 and status in C2, this returns Eligible for a score of 75 and status Complete, but Not eligible if either condition fails: =IF(AND(B2>=70,C2="Complete"),"Eligible","Not eligible")
Now suppose an order qualifies for review if it is either urgent or worth at least 1,000. With the urgency label in A2 and order amount in B2, this formula returns Review if A2 is Urgent or B2 is at least 1,000. If A2 is Standard and B2 is 800, it returns Normal: =IF(OR(A2="Urgent",B2>=1000),"Review","Normal")
AND and OR can each evaluate multiple conditions, separated by commas in a standard English-language Excel setup. Use parentheses to make the structure clear when combining them. For example, a condition that requires one criterion and either of two other criteria can be built with AND around an OR. When the logic gets difficult to explain in a sentence, test it with a few deliberately chosen rows before relying on the output.
Entering formulas and avoiding common problems
In Excel for Microsoft 365 on Windows, select the cell where the answer should appear, type an equals sign followed by the IF formula, and press Enter. The same IF function is available in Excel for Mac and Excel for the web. On Mac, the function itself works the same way; menu and keyboard details can differ, but there is no separate Mac version of the IF formula.
Use commas between arguments in the examples here. Excel’s list separator can depend on regional settings, so some installations expect semicolons instead. If Excel rejects a formula that otherwise looks correct, check the separator used by your installation and replace the commas consistently if necessary. Do not mix commas and semicolons in one formula.
Common issues to check include:
- Missing quotation marks: text such as Pass must be enclosed in straight double quotation marks. A cell reference such as A2 should not be quoted.
- Wrong comparison boundary: decide whether the threshold is inclusive. Use >= for “at least” and > for “more than.”
- Text that does not match: a check for Complete may fail if the cell contains a different word or extra spaces. Excel’s ordinary text equality comparisons are not case-sensitive, but spelling and spaces still matter.
- Unexpected zero: a blank cell used in arithmetic can behave like zero. Add a blank check if an unfinished row should not show a numeric result.
- Unbalanced parentheses: each opening parenthesis needs a closing one. In nested IF formulas, count the pairs and inspect each true and false result.
If the formula appears as text instead of calculating, check that the cell is not formatted as Text and that the entry begins with an equals sign. You can also select the cell, change its number format to General, and re-enter the formula. A leading apostrophe can also make Excel treat an entry as text.
When to use IF—and when not to
IF is a good choice when a result depends on a small, explicit decision: pass or fail, apply a simple fee or do not, show a reminder or leave the cell blank. It is also useful as one part of a larger calculation. Before adding IF, though, ask whether the result could be expressed more simply.
For example, if the desired output is simply TRUE when A2 is greater than zero and FALSE otherwise, the comparison itself already returns TRUE or FALSE; wrapping it in IF is unnecessary. Conversely, if the result needs readable labels such as Positive and Not positive, IF is appropriate. For a larger set of categories, consider a lookup table so a colleague can change the rules without editing a long formula.
IF is not the same as IFERROR. IF evaluates a condition you specify; IFERROR handles a formula result that produces an error. An IF formula does not automatically catch errors in its test or result. Choose the function based on the problem: use IF for a decision, and consider error-handling functions only when you specifically need to handle errors.
Frequently Asked Questions
What is the basic IF formula in Excel?
The basic pattern is a test followed by the result for true and the result for false. For example, if a value is in A2, =IF(A2>=60,"Pass","Fail") checks whether it is at least 60 and returns the corresponding label.
Can an IF formula return a blank cell?
It can return an empty string, written as two double quotation marks with nothing between them. The result looks blank, but the cell still contains a formula and is not genuinely empty.
Can I use more than one condition in IF?
Yes. Put AND inside the logical test when all conditions must be true, or OR when any one of them is enough. IF then returns its true or false result based on the combined test.
Why does my IF formula show an error?
Check that the three arguments are in the right order, text results have straight double quotation marks, parentheses are balanced, and your Excel installation uses the argument separator you typed. Also confirm that references point to the intended cells.
How many IF functions can I nest?
Excel allows nested IF formulas, but a long chain is difficult to read and maintain. For a handful of outcomes, nesting can be practical; for many categories or frequently changing rules, a lookup table is often clearer.
Related
- Microsoft Excel Compare Two Sheets: Methods That Work
- Microsoft Excel: How to Change the Print Area
- Merge Cells but Keep All Text in Excel: Safe Methods
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- VLOOKUP Showing Formula? Causes and Fixes in ExcelIf VLOOKUP is showing as text instead of returning a result, first turn off Formulas > Show Formulas;…
- Excel SUM Without Hidden Cells: Which Formula to UseTo sum only visible rows in Excel, use SUBTOTAL with function number 109. With amounts in B2:B6 and…
- Excel Extend Number Sequence: Fill Series and FormulasTo extend a number sequence in Excel, enter its first two values, select both cells, then drag the…
- Excel Text Join With a New Line: Formulas and TipsTo join text with a new line in Excel, use TEXTJOIN with CHAR(10) as the delimiter. With text…
- Round Excel Without Decimals: Formula or Formatting?To round a value in Excel to the nearest whole number, use =ROUND(A1,0) when the value is in…
- Excel IFERROR: How It Works, Examples, and Common UsesExcel’s IFERROR checks a value or formula and returns that result if it is not an error; if…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.