Menu
Coddy logo textTech

The IF Function

Part of the Fundamentals section of Coddy's Excel journey — lesson 34 of 42.

So far every formula gave one answer, no matter what. But real life is full of decisions: if it's raining, take an umbrella, otherwise, sunglasses. Excel makes decisions with the IF function:

=IF(condition, value_if_true, value_if_false)

IF takes exactly three parts, separated by commas. First a condition, a question with a yes/no answer, like A1>=60 ("is A1 at least 60?"). Then the answer to show when the condition is true, and finally the answer when it's false.

=IF(A1>=60, "pass", "fail")

If A1 holds 75, this shows pass. Change A1 to 40 and the very same formula shows fail, the formula re-decides every time the data changes. Notice the quotes around pass and fail: text answers always go in double quotes, so Excel knows they're words to display, not cell names.

The answers don't have to be text. =IF(A1>100, A1*0.9, A1) gives a 10% discount only on orders over 100, numbers, formulas and text all work as the true/false answers. One question, two possible outcomes: that's IF.

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals