IF function

The IF function returns one value if a condition is true and another (or nothing) if it is false, letting you branch logic in a cell.

=IF(logical_test, value_if_true, [value_if_false])

Generate a IF formula

Describe what you need. The generator will reach for IF where IF is the right tool, and tell you when it is not.

How to get a better answer
  • Name your columns by letter and by header: "column F (Net Value)" beats "the amount column".
  • State every condition, including the negatives — "not cancelled" changes the formula's shape.
  • Say where the data starts if it is not row 1, and whether it will grow.
  • Check the settings above match your spreadsheet: the wrong argument separator is a syntax error on your machine.

Arguments

How IF reads its arguments
logical_testrequiredvalue_if_truerequiredvalue_if_falseoptionalIF
ArgumentRequiredDescription
logical_testRequiredRequired; any expression that evaluates to TRUE or FALSE – non-boolean values that cannot be coerced trigger a #VALUE! error.
value_if_trueRequiredRequired; the result returned when logical_test is TRUE – can be a constant, reference, or another formula.
value_if_falseOptionalOptional; the result returned when logical_test is FALSE – if omitted the function returns FALSE.

Returns

It returns a single value of any type (number, text, logical, or error) matching the shape of the chosen branch.

Availability

Excel: All · Google Sheets: Supported

Worked examples

1. Mark listings as Hot or Cold based on price and market time

AddressBedsBathsList PriceDays on Market
123 Maple St3227500025
456 Oak Ave4335000045
=IF(AND(D2<300000, E2<30), "Hot", "Cold")

Result: Hot

The logical_test uses AND to require both a list price under $300,000 and fewer than 30 days on market. For the first row, D2 is 275000 and E2 is 25, so both conditions are TRUE and the IF returns "Hot". The second row fails the price test, so IF would return "Cold" for that row.

2. Label properties with three or more bedrooms

AddressBedsBathsList PriceDays on Market
789 Pine Rd2121000012
321 Cedar Ln322950008
=IF(B2>=3, "3+ Beds", "Less than 3")

Result: Less than 3

The logical_test checks whether the Beds column (B2) is greater than or equal to 3. In the first row B2 equals 2, so the test is FALSE and IF returns the second argument "Less than 3". In the second row B2 equals 3, making the test TRUE, so the function would return "3+ Beds" for that entry.

3. Show price or indicate missing data

AddressBedsBathsList PriceDays on Market
654 Spruce Ct4320
987 Birch Blvd544200005
=IF(D2="", "N/A", D2)

Result: N/A

Here the logical_test tests whether the List Price cell (D2) is empty. For the first row D2 contains an empty string, so the test is TRUE and IF returns the text "N/A". When a price exists, as in the second row, the test is FALSE and the actual price value (420000) is returned.

Common errors

Which IF error are you seeing?
IF returned an error#VALUE!
Compare the text explicitly, e.g., =IF(A2="Yes",1,0), so the test resolves to a proper boolean.
#DIV/0!
Guard the division with an additional check or wrap it in IFERROR, such as =IF(C2<>0, IF(C2/0>0,"OK","Bad"), FALSE).
#REF!
Update the formula to point to a valid column or use structured table references that adjust automatically when columns are moved.
ErrorWhy it happensHow to fix it
#VALUE!The logical_test supplied a plain text string like "Yes" that cannot be coerced to TRUE/FALSE, so IF raises a #VALUE! error.Compare the text explicitly, e.g., =IF(A2="Yes",1,0), so the test resolves to a proper boolean.
#DIV/0!A division by zero occurs inside the logical_test, for example =IF(C2/0>0,"OK","Bad"), causing the error to propagate before IF can decide which branch to take.Guard the division with an additional check or wrap it in IFERROR, such as =IF(C2<>0, IF(C2/0>0,"OK","Bad"), FALSE).
#REF!The formula references a cell that no longer exists, like =IF(F2>0,"Yes","No") after column F has been deleted, leading to a #REF! reference error.Update the formula to point to a valid column or use structured table references that adjust automatically when columns are moved.

Tips and when to use something else

  • Nest IF inside AND or OR to test multiple conditions without writing separate IF statements.
  • When you have more than three mutually exclusive outcomes, consider using IFS for cleaner syntax.
  • Remember that IF can return arrays in modern Excel; if you only need a single result, wrap the formula in INDEX(...,1).
  • If you need to handle errors from the true/false branches themselves, combine IF with IFERROR or IFNA instead of checking each branch manually.

Frequently asked questions

Can IF be used to return different data types in the same formula?
Yes. IF can return numbers, text, logical values, or even errors, as long as the two possible results are compatible with the surrounding context. For example, =IF(A2>0, A2*100, "No price") mixes numeric and text outcomes, which Excel will display without error.
Why does my IF formula return FALSE even though the condition looks true?
Excel treats any non-zero number as TRUE, but text that isn’t explicitly compared will cause #VALUE!. Verify that the logical_test really evaluates to a boolean by using explicit comparisons like =IF(A2="Yes",…) or by wrapping calculations in ISNUMBER or ISTEXT as needed.
How can I avoid writing many nested IF statements for tiered pricing?
Use the IFS function, which lets you list condition/value pairs without deep nesting. For example, IFS(D2<200000,"Low", D2<400000,"Medium", D2>=400000,"High") replaces three nested IFs in a single, readable call.
What is the difference between IF and SWITCH for multiple conditions?
IF evaluates a single logical expression, while SWITCH matches a single expression against a list of possible values. SWITCH is more concise when you have one variable compared to many constants, whereas IF (or IFS) is better for complex logical tests involving inequalities or multiple columns.

Need a different formula?

The full generator is not scoped to one function — describe any spreadsheet problem and it will pick.

Open the formula generator