How to use the Excel IF function
How to use the Excel IF function
exceljet.net
Excel IF Function
Send to Kindle
The IF function runs a logical test and returns one value for a TRUE result, and
another value for a FALSE result. The first argument, logical_test, is an expression
that should return either TRUE or FALSE. The second argument, value_if_true, is
the value to return when logical_test returns TRUE. The last
argument, value_if_false, is the value to return when logical_test returns FALSE.
Both value_if_true and value_if_false are optional, but at least one of them must be
provided. The result from IF can be a value, a cell reference, or even another
formula.
=IF(C5>=70,"Pass","Fail")
Translation: If the value in C5 is greater than or equal to 70, return "Pass". Otherwise,
return "Fail".
Note that the logical flow of this formula can be reversed. This formula returns
the same result:
Translation: If the value in C5 is less than 70, return "Fail". Otherwise, return "Pass".
https://exceljet.net/excel-functions/excel-if-function 1/5
9/9/22, 12:11 AM Mercury Reader
Both formulas above, when copied down, will return correct results.
Note: If you are new to the idea of formula criteria, this article explains many examples.
=IF(B5="red",100,IF(B5="blue",125))
Translation: IF the value in B5 is "red", return 100. Else, if the value in B5 is "blue",
return 125.
Assign points based on color with the IF There are three things to
1. The formula will return FALSE if the value in B5 is anything except "red" or
"blue"
2. The text values "red" and "blue" must be enclosed in double quotes ("")
3. The IF function is not case-sensitive and will match "red" or "Red" or "RED"
This is a simple example of "nested IFs"; see below for a more complex example.
Nested IF statements
The IF function can be "nested". A "nested IF" refers to a formula where at least
one IF function is nested inside another in order to test for more conditions and
return more possible results. Each IF statement needs to be carefully "nested"
inside another so that the logic is correct.
For example, the following formula can be used to assign a grade rather than a
pass / fail result:
=IF(C6<70,"F",IF(C6<75,"D",IF(C6<85,"C",IF(C6<95,"B","A"))))
Note: the newer IFS function is designed to handle multiple conditions without nesting.
Logical operators
When you are constructing a test with IF, you can use any of the following logical
operators:
https://exceljet.net/excel-functions/excel-if-function 3/5
9/9/22, 12:11 AM Mercury Reader
The IF function doesn't support wildcards, but you can combine IF with
COUNTIF to get basic wildcard functionality.
=IF(AND(A1>7,A1<10),"OK","")
Translation: if A1 is greater than 7 and less than 10, return "OK". Otherwise, return
nothing ("").
To return B1+10 when A1 is "red" or "blue" you can use the OR function like this:
=IF(OR(A1="red",A1="blue"),B1+10,B1)
=IF(NOT(A1="red"),B1+10,B1)
https://exceljet.net/excel-functions/excel-if-function 4/5
9/9/22, 12:11 AM Mercury Reader
More information
Notes
The IF function is not case-sensitive.
To count values conditionally, use the COUNTIF or the COUNTIFS
functions.
To sum values conditionally, use the SUMIF or the SUMIFS functions.
If any of the arguments to IF are supplied as arrays, the IF function will
evaluate every element of the array.
https://exceljet.net/excel-functions/excel-if-function
https://exceljet.net/excel-functions/excel-if-function 5/5