Check if function in excel

IF function

The IF function is one of the most popular functions in Excel, and it allows you to make logical comparisons between a value and what you expect.

So an IF statement can have two results. The first result is if your comparison is True, the second if your comparison is False.

For example, =IF(C2=”Yes”,1,2) says IF(C2 = Yes, then return a 1, otherwise return a 2).

Your browser does not support video. Install Microsoft Silverlight, Adobe Flash Player, or Internet Explorer 9.

Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it’s false.

IF(logical_test, value_if_true, [value_if_false])

For example:

  • =IF(A2>B2,»Over Budget»,»OK»)

  • =IF(A2=B2,B4-A4,»»)

Argument name

Description

logical_test    (required)

The condition you want to test.

value_if_true    (required)

The value that you want returned if the result of logical_test is TRUE.

value_if_false    (optional)

The value that you want returned if the result of logical_test is FALSE.

Simple IF examples

Cell D2 contains a formula =IF(C2="Yes",1,2)

  • =IF(C2=”Yes”,1,2)

In the above example, cell D2 says: IF(C2 = Yes, then return a 1, otherwise return a 2)

Cell D2 contains the formula =IF(C2=1,"YES","NO")

  • =IF(C2=1,”Yes”,”No”)

In this example, the formula in cell D2 says: IF(C2 = 1, then return Yes, otherwise return No)As you see, the IF function can be used to evaluate both text and values. It can also be used to evaluate errors. You are not limited to only checking if one thing is equal to another and returning a single result, you can also use mathematical operators and perform additional calculations depending on your criteria. You can also nest multiple IF functions together in order to perform multiple comparisons.

Formula in cell D2 is =IF(C2>B2,”Over Budget”,”Within Budget”)

  • =IF(C2>B2,”Over Budget”,”Within Budget”)

In the above example, the IF function in D2 is saying IF(C2 Is Greater Than B2, then return “Over Budget”, otherwise return “Within Budget”)

Formula in cell E2 is =IF(C2>B2,C2-B2,"")

  • =IF(C2>B2,C2-B2,0)

In the above illustration, instead of returning a text result, we are going to return a mathematical calculation. So the formula in E2 is saying IF(Actual is Greater than Budgeted, then Subtract the Budgeted amount from the Actual amount, otherwise return nothing).

Formula in Cell F7 is IF(E7=”Yes”,F5*0.0825,0)

  • =IF(E7=”Yes”,F5*0.0825,0)

In this example, the formula in F7 is saying IF(E7 = “Yes”, then calculate the Total Amount in F5 * 8.25%, otherwise no Sales Tax is due so return 0)

Note: If you are going to use text in formulas, you need to wrap the text in quotes (e.g. “Text”). The only exception to that is using TRUE or FALSE, which Excel automatically understands.

Common problems

Problem

What went wrong

0 (zero) in cell

There was no argument for either value_if_true or value_if_False arguments. To see the right value returned, add argument text to the two arguments, or add TRUE or FALSE to the argument.

#NAME? in cell

This usually means that the formula is misspelled.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

Connect with an expert. Learn from live instructors.

See Also

IF function — nested formulas and avoiding pitfalls

IFS function

Using IF with AND, OR and NOT functions

COUNTIF function

How to avoid broken formulas

Overview of formulas in Excel

Need more help?

What is IF Function in Excel?

IF function in Excel evaluates whether a given condition is met and returns a value depending on whether the result is “true” or “false”. It is a conditional function of Excel, which returns the result based on the fulfillment or non-fulfillment of the given criteria.

For example, the IF formula in Excel can be applied as follows:

 “=IF(condition A,“value B”,“value C”)”

 The IF excel function returns “value B” if condition A is met and returns “value C” if condition A is not met.

It is often used to make logical interpretations which help in decision-making.

Table of contents
  • What is IF Function in Excel?
    • Syntax of the IF Excel Function
    • How to Use IF Function in Excel?
      • Example #1
      • Example #2
      • Example #3
      • Example #4
      • Example #5
    • Guidelines for the Multiple IF Statements
    • Frequently Asked Question
    • IF Excel Function Video
    • Recommended Articles

Syntax of the IF Excel Function

The syntax of the IF function is shown in the following image:

Excel IF Formula

The IF excel function accepts the following arguments:

  • Logical_test: It refers to the condition to be evaluated. The condition can be a value or a logical expression.
  • Value_if_true: It is the value returned as a result when the condition is “true”.
  • Value_if_false: It is the value returned as a result when the condition is “false”.

In the formula, the “logical_test” is a required argument, whereas the “value_if_true” and “value_if_false” are optional arguments.

The IF formula uses logical operators to evaluate the values in a range of cells. The following table shows the different logical operatorsLogical operators in excel are also known as the comparison operators and they are used to compare two or more values, the return output given by these operators are either true or false, we get true value when the conditions match the criteria and false as a result when the conditions do not match the criteria.read more and their meaning.

Operator Meaning
= Equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
<> Not equal to

How to Use IF Function in Excel?

Let us understand the working of the IF function with the help of the following examples in Excel.

You can download this IF Function Excel Template here – IF Function Excel Template

Example #1

If there is no oxygen on a planet, life is impossible. If oxygen is available on a planet, then life is possible. The following table shows a list of planets in column A and the information on the availability of oxygen in column B. We have to find the planets where life is possible, based on the condition of oxygen availability.

IF Function Example 1

Let us apply the IF formula to cell C2 to find out whether life is possible on the planets listed in the table.

The IF formula is stated as follows:

“=IF(B2=“Yes”, “Life is Possible”, “Life is Not Possible”)

The succeeding image shows the IF formula applied to cell C2.

IF Function Example 1-2

The subsequent image shows how the IF formula is applied to the range of cells C2:C5.

IF Function Example 1-4

Drag the cells to view the output of all the planets.

IF Function Example 1-3

The output in the below worksheet shows life is possible on the planet Earth.

Flow Chart of Generic IF Excel Function

Flow Chart of IF Function

The IF Function Flow Chart for Mars (Example #1)

Flow Chart of IF Function 1

The flow of IF function flowchart for Jupiter and Venus is the same as the IF function flowchart for Mars (Example #1).

The IF Function Flow Chart for Earth

Flow Chart of IF Function 2

Hence, the IF excel function allows making logical comparisons between values. The modus operandi of the IF function is stated as: If something is true, then do something; otherwise, do something else.

Example #2

The following table shows a list of years. We want to find out if the given year is a leap year or not.

A leap year has 366 days; the extra day is the 29th of February. The criteria for a leap year are stated as follows:

  1. The year will be exactly divisible by 4 and not exactly be divisible by 100 or
  2. The year will be exactly divisible by 400.

IF Function Example 2

In this example, we will use the IF function along with the AND, OR, and MOD functions to find the leap years.

We use the MOD function to find a remainder after a dividend is divided by a divisor.

The AND functionThe AND function in Excel is classified as a logical function; it returns TRUE if the specified conditions are met, otherwise it returns FALSE.read more evaluates both the conditions of the leap years for the value “true”. The OR functionThe OR function in Excel is used to test various conditions, allowing you to compare two values or statements in Excel. If at least one of the arguments or conditions evaluates to TRUE, it will return TRUE. Similarly, if all of the arguments or conditions are FALSE, it will return FASLE.read more evaluates either of the condition for the value “true”.

We will apply the MOD function to the conditions as follows:

If MOD(year,4)=0 and MOD(year,100)<>(is not equal to) 0, then the year is a leap year.

or

If MOD(year,400)=0, then the year is a leap year; otherwise, the year is not a leap year.

The IF formula is stated as follows:

“=IF(OR(AND((MOD(year,4)=0),(MOD(year,100)<>0)),(MOD(year,400)=0)),“Leap Year”, “Not A Leap Year”)”

The argument “year” refers to a reference value.

The following images show the output of the IF formula applied in the range of cells.

IF Function Example 2-1

IF Function Example 2-2

The following image shows how the IF formula is applied to the range of cells B2:B18.

IF Function Example 2-4

The succeeding table shows the years 1960, 2028, and 2148 as leap years and the remaining as non-leap years.

IF Function Example 2-3

The result of the IF excel formula is displayed for the range of cells B2:B18 in the following image.

IF Function Example 2-5

Example #3

The succeeding table shows a list of drivers and the directions they undertook to reach the destination.  It is preceded by an image of the road intersection explaining the turns taken by the drivers and their destinations. The right turn leads to town B, and the left turn leads to town C. Identify the driver’s destination to town B and town C.

Road Intersection Image

IF Function (Destination Example)

IF Function Example 3-1

Let us apply the IF excel function to find the destination. Here, the condition is mentioned as follows:

  • If the driver turns right, he/she reaches town B.
  • If the driver turns left, he/she reaches town C.

We use the following IF formula to find the destination:

 “=IF(B2=“Left”, “Town C”, “Town B”)”

The succeeding image shows the output of the IF formula applied to cell C2.

IF Function Example 3-2

Drag the cells to use the formula in the range C2:C11. Finally, we get the destinations of each driver for their turning movements.

The below image displays the IF formula applied to the range.

IF Function Example 3-3

The output of the IF formula and the destinations are displayed in the succeeding image.

IF Function Example 3-4

The result shows that six drivers reached town C, and the remaining four have reached town B.

Example #4

The following table shows a list of items and their inventory levels. We want to check if the specific item is available in the inventory or not using the IF function.

Example 4

Let us list the name of items in column A and the number of items in column B. The list of data to be validated for the entire items list is shown in the cell E2 of the below image.

Example 4-1

We use the Excel IF along with the VLOOKUP functionThe VLOOKUP excel function searches for a particular value and returns a corresponding match based on a unique identifier. A unique identifier is uniquely associated with all the records of the database. For instance, employee ID, student roll number, customer contact number, seller email address, etc., are unique identifiers.
read more
to check the availability of the items in the inventory.

The VLOOKUP function looks up the values referring to the number of items, and the IF function will check whether the item number is greater than zero or not.

We will apply the following IF formula in the F2 cell:

“=IF(VLOOKUP(E2,A2:B11,2,0)=0, “Item Not Available”,“Item Available”)”

If the lookup value of an item is equal to 0, then the item is not available; else, the item is available.

The succeeding image shows the result of the IF formula in the cell F2.

Example 4-2

Select “bat” in the E2 item cell to know whether the item is available or not in the inventory (as shown in the following image).

Example 4-3

Example #5

The following table shows the list of students and their marks. The grade criteria are provided based on the marks obtained by the students.  We want to find the grade of each student in the list.

Example 4-4

We apply the  Nested IF in Excel since we have multiple criteria to find and decide each student’s grade.

The Nesting of IF function uses the IF function inside another IF formula when multiple conditions are to be fulfilled.

The syntax of Nesting of IF function is stated as follows:

“=IF( condition1, value_if_true1, IF( condition2, value_if_true2, value_if_false2 ))”

The succeeding table represents the range of scores and the grades, respectively.

Example 4-5

Let us apply the multiple IF conditions with AND function in the below-nested formula to find out the grade of the students:

“=IF((B2>=95),“A”,IF(AND(B2>=85,B2<=94),“B”,IF(AND(B2>=75,B2<=84),“C”,IF(AND(B2>=61,B2<=74),“D”,“F”))))”

The IF function checks the logical condition as shown in the formula below:

“=IF(logical_test, [value_if_true],[value_if_false])”

We will split the above-mentioned nested formula and check the IF statements as shown below:

First Logical Test: B2>=95

If the formula returns,

  • Value_if_true, execute: “A” (Grade A) else(comma) enter value_if_false
  • Value_if_false, then the formula finds another IF condition and enter IF condition

Second Logical Test: B2>=85(logical expression 1) and B2<=94(logical expression 2)

(We use AND function to check the multiple logical expressions as the two given conditions are to be evaluated for “true.”)

If the formula returns,

  • Value_if_true,  execute: “B” (Grade B) else(comma) enter value_if_false
  • Value_if_false, then the formula finds another IF condition and enter IF condition

Third Logical Test: B2>=75(logical expression 1) and B2<=84(logical expression 2)

(We use AND function to check the multiple logical expressions as the two given conditions are to be evaluated for “true.”)

If the formula returns,

  • Value_if_true,  execute: “C” (Grade C) else(comma) enter value_if_false
  • value_if_false, then the formula finds another IF condition and enter IF condition

Fourth Logical Test: B2>=61(logical expression 1) and B2<=74(logical expression 2)

(We use AND function to check the multiple logical expressions as the two given conditions are to be evaluated for “true.”)

If the formula returns,

  • Value_if_true, execute: “D” (Grade D) else(comma) enter value_if_false
  • Value_if_false, execute: “F” (Grade F)
  • Finally, close the parenthesis.

 The below image displays the output of the IF formula applied to the range.

Example 4-6

The succeeding image shows the IF nested formula applied to the range.

Example 4-7

The grades of the students are listed in the following table.

Example 4-8

Guidelines for the Multiple IF Statements

The guidelines for the multiple IF statements are listed as follows:

  • Use nested IF function to a limited extent as multiple IF statements require a great deal of thought to be accurate.
  • Multiple IF statementsIn Excel, multiple IF conditions are IF statements that are contained within another IF statement. They are used to test multiple conditions at the same time and return distinct values. Additional IF statements can be included in the ‘value if true’ and ‘value if false’ arguments of a standard IF formula.read more require multiple parentheses (), which is often difficult to manage. Excel provides a way to check the color of each opening and closing parenthesis to avoid this situation. The last closing parenthesis color will always be black, denoting the end of the formula statement.
  • Whenever we pass a string value for the arguments “value_if_true” and “value_if_false” or test a reference against a string value, enclose the string value in double quotes. Passing a string value without quotes will result in “#NAME?” error.

Frequently Asked Question

1. What is the IF function in Excel?

The Excel IF function is a logical function that checks the given criteria and returns one value for a “true” and another value for a “false” result.

The syntax of the IF function is stated as follows:
“=IF(logical_test, [value_if_true], [value_if_false])”

The arguments are as follows:
1. Logical_test – It refers to a value or condition that is tested.
2. Value_if_true – It is the value returned when the condition logical_test is “true.”
3. Value_if_false – It is the value returned when the condition logical_test is “false.”

The “logical_test” is a required argument, whereas the “value_if_true” and “value_if_false” are optional arguments.

2. How to use the IF Excel function with multiple conditions?

The IF Excel statement for multiple conditions is created by using multiple IF functions in a single formula.

The syntax of IF function with multiple conditions is stated as follows:

“=IF (condition 1_“true”, do something, IF (condition 2_“true”, do something, IF (condition 3_ “true”, do something, else do something)))”

3. How to use the function IFERROR in Excel?

IF Excel Function Video

Recommended Articles

This has been a guide to the IF function in Excel. Here we discuss how to use the IF function along with examples and downloadable templates. You may also look at these useful functions –

  • What is the Logical Test in Excel?A logical test in Excel results in an analytical output, either true or false. The equals to operator, “=,” is the most commonly used logical test.read more
  • “Not Equal to” in Excel“Not Equal to” argument in excel is inserted with the expression <>. The two brackets posing away from each other command excel of the “Not Equal to” argument, and the user then makes excel checks if two values are not equal to each other.read more
  • Data Validation ExcelThe data validation in excel helps control the kind of input entered by a user in the worksheet.read more

Excel IF Function – Introduction

Excel IF Function

When to use Excel IF Function

IF function in Excel is best suited for situations where you check whether a condition is TRUE or FALSE. If it’s TRUE, the function returns a specified value/reference, and if not then it returns another specified value/reference.

What it Returns

It returns whatever value you specify for the TRUE or FALSE condition.

Syntax

=IF(logical_test, [value_if_true], [value_if_false])

Input Arguments

  • logical_test – this is the condition that you want to test. It could be a logical expression that can evaluate to TRUE or FALSE. This can either be a cell reference, a result of some other formula, or can be manually entered.
  • [value_if_true] – (Optional) This is the value that is returned when the logical_test evaluates to TRUE.
  • [value_if_false] – (Optional) This is the value that is returned when the logical_test evaluates to FALSE.

Important Notes About using IF Function in Excel

  • A maximum of 64 nested IF conditions can be tested in the formula.
  • If any of the argument is an array, each element of the array is evaluated.
  • If you omit the FALSE argument (value_if_false), i.e., there is only a comma after the  value_if_true argument, the function would return a 0 when the condition is FALSE.
    • For example, in the example below, the formula is =IF(A1>20,”Approve”,), where the value_if_false is not specified, however, the value_if_true argument is still followed by a comma. This would return 0 whenever the checked condition is not met.Excel If Function - When False is ommitted
  • If you omit the TRUE argument (value_if_true), and specify only the value_if_false argument, the function would return a 0 when the condition is TRUE.
    • For example, in the example below, the formula is =IF(A1>20,,”Approve”), where the value_if_true is not specified (only a comma is used to then specify the value_if_false value). This would return 0 whenever the checked condition is met.Excel If Function - When TRUE is ommitted

Excel IF Function – Examples

Here are five practical examples of using the IF function in Excel.

Example 1: Using Excel IF function to Check a Simple Numeric Condition

When using Excel IF function with numbers, you can use a variety of operators to check a condition. Here is a list of operators you can use:

Excel If Function - Operators

Below is a simple example where students marks are checked. If the marks are more than or equal to 35, the function returns Pass, else it returns Fail.

Excel If Function - pass fail

Example 2: Using Nested IF to Check a Sequence of Conditions

Excel IF Function can take up to 64 conditions at once. While it’s inadvisable to create long Nested IF functions, in the case of limited conditions, you can create a formula that checks conditions in a sequence.

In the example below, we check for two conditions.

  • The first condition checks whether the marks are less than 35. If this is TRUE it returns Fail.
  • In case the first condition is FALSE, which means that the student scored above or equal to 35, it checks for another condition. It checks if the marks are greater than or equal to 75. If this is true, it returns Distinction, else it simply returns Pass.

Excel If Function - Nested

Example 3: Calculating Commissions Using Excel IF Function

Excel If Function allows you to perform calculations in the value section. A good example of this is calculating the sales commission for sales rep using the IF function.

In the example below, a sales rep gets no commission if the sales are less than 50K, gets a 2% commission if the sales are between 50-100K and 4% commission if the sales are more than 100K.

Here is the formula used:

=IF(B2<50,0,If(B2<100,B2*2%,B2*4%))

Excel If Function - Commission

In the formula used in the example above, the calculation is done within the IF function itself. When the sales value is between 50-100K, it returns B2*2%, which is the 2% commission based on the sales value.

Example 4: Using Logical Operators (AND/OR) in Excel IF Function

You can use logical operators (AND/OR) within the IF function to test multiple conditions at once.

For example, suppose you’ve to select students for the scholarship based on marks and attendance. In the example shown below, a student is eligible only if he scores more than 80 and has the attendance of more than 80%.

using-excel-if-function-and-operator-data

You can use the AND function within the IF function to first check whether both these conditions are met or not. If the conditions are met, the function returns Eligible, else it returns Not Eligible.

Here is the formula that will do this:

=IF(AND(B2>80,C2>80%),”Yes”,”No”)

using-excel-if-function-and-operator

Example 5: Converting all Errors to Zero using Excel IF function

Excel IF function can also be used to get rid of cells that contain errors. You can convert the error values to blanks or zeros or any other value.

Here is the formula that will do it:

=IF(ISERROR(A1),0,A1)

The formula returns a 0 when there is an error value, else it returns the value in the cell.

NOTE: If you’re using Excel 2007 or versions after it, you can also use the IFERROR function to do this. 

Similarly, you can also handle blank cells. In case of blank cells, use the ISBLANK function as shown below:

=IF(ISBLANK(A1),0,A1)

Excel If Function - isblank

Excel IF Function – Video Tutorial

Related Excel Functions:

  • Excel AND Function.
  • Excel OR Function.
  • Excel NOT Function.
  • Excel IFS Function.
  • Excel IFERROR Function.
  • Excel FALSE Function.
  • Excel TRUE Function

Other Excel tutorials you may find useful:

  • Avoid Nested IF Function in Excel by using VLOOKUP

The IF function runs a logical test and returns one value for a TRUE result, and another value for a FALSE result. The result from IF can be a value, a cell reference, or even another formula. By combining the IF function with other logical functions like AND and OR, you can test more than one condition at a time.

Syntax

The generic syntax for the IF function looks like this:

=IF(logical_test,[value_if_true],[value_if_false])

The first argument, logical_test, is typically an expression that returns either TRUE or FALSE. The second argument, value_if_true, is the value to return when logical_test is TRUE. The last argument, value_if_false, is the value to return when logical_test is FALSE. Both value_if_true and value_if_false are optional, but you must provide one or the other. For example, if cell A1 contains 80, then:

=IF(A1>75,TRUE) // returns TRUE
=IF(A1>75,"OK") // returns "OK"
=IF(A1>85,"OK") // returns FALSE
=IF(A1>75,10,0) // returns 10
=IF(A1>85,10,0) // returns 0
=IF(A1>75,"Yes","No") // returns "Yes"
=IF(A1>85,"Yes","No") // returns "No"

Notice that text values like «OK», «Yes», «No», etc. must be enclosed in double quotes («»). However, numeric values should not be enclosed in quotes.

Logical tests

The IF function supports logical operators (>,<,<>,=) when creating logical tests. Most commonly, the logical_test in IF is a complete logical expression that will evaluate to TRUE or FALSE. The table below shows some common examples:

Goal Logical test
If A1 is greater than 75 A1>75
If A1 equals 100 A1=100
If A1 is less than or equal to 100 A1<=100
If A1 equals «Red» A1=»red»
If A1 is not equal to «Red» A1<>»red»
If A1 is less than B1 A1<B1
If A1 is empty A1=»»
If A1 is not empty A1<>»»
If A1 is less than current date A1<TODAY()

Notice text values must be enclosed in double quotes («»), but numbers do not. The IF function does not support wildcards, but you can combine IF with COUNTIF to get basic wildcard functionality. To test for substrings in a cell, you can use the IF function with the SEARCH function.

Pass or Fail example

In the worksheet shown above, we want to assign either «Pass» or «Fail» based on a test score. A passing score is 70 or higher. The formula in D6, copied down, is:

=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:

=IF(C5<70,"Fail","Pass")

Translation: If the value in C5 is less than 70, return «Fail». Otherwise, return «Pass».

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.

Assign points based on color

In the worksheet below, we want to assign points based on the color in column B. If the color is «red», the result should be 100. If the color is «blue», the result should be 125. This requires that we use a formula based on two IF functions, one nested inside the other. The formula in C5, copied down, is:

=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 function

There are three things to notice in this example:

  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», «Red», «RED», or «rEd».

This is a simple example of a nested IFs formula. See below for a more complex example.

Return another formula

The IF function can return another formula as a result. For example, the formula below will return A1*5% when A1 is less than 100, and A1*7% when A1 is greater than or equal to 100:

=IF(A1<100,A1*5%,A1*7%)

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"))))

Up to 64 IF functions can be nested. However, in general, you should consider other functions, like VLOOKUP or XLOOKUP for more complex scenarios, because they can handle more conditions in a more streamlined fashion. For a more details see this article on nested IFs.

Note: the newer IFS function is designed to handle multiple conditions without nesting. However, a lookup function like VLOOKUP or XLOOKUP is usually a better approach unless the logic for each condition is custom.

IF with AND, OR, NOT

The IF function can be combined with the AND function and the OR function. For example, to return «OK» when A1 is between 7 and 10, you can use a formula like this:

=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)

Translation: if A1 is red or blue, return B1+10, otherwise return B1.

=IF(NOT(A1="red"),B1+10,B1)

Translation: if A1 is NOT red, return B1+10, otherwise return B1.

IF cell contains specific text

Because the IF function does not support wildcards, it is not obvious how to configure IF to check for a specific substring in a cell. A common approach is to combine the ISNUMBER function and the SEARCH function to create a logical test like this:

=ISNUMBER(SEARCH(substring,A1)) // returns TRUE or FALSE

For example, to check for the substring «xyz» in cell A1, you can use a formula like this:

=IF(ISNUMBER(SEARCH("xyz",A1)),"Yes","No")

Read a detailed explanation here.

More information

  • Read more about nested IFs
  • Learn how to use VLOOKUP instead of nested IFs (video)
  • 50 Examples of formula criteria

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.

IF function is undoubtedly one of the most important functions in excel. In general, IF statements give the desired intelligence to a program so that it can make decisions based on given criteria and, most importantly, decide the program flow.

In Microsoft Excel terminology, IF statements are also called «Excel IF-Then statements». IF function evaluates a boolean/logical expression and returns one value if the expression evaluates to ‘TRUE’ and another value if the expression evaluates to ‘FALSE’.
EXCEL-IF FUNCTION

Definition of Excel IF Function

According to Microsoft Excel, IF function is defined as a formula which «checks whether a condition is met, returns one value if true and another value if false».

Syntax

Syntax of IF function in Excel is as follows:

=IF(logic_test, [value_if_true], [value_if_false])

'logic_test' (required argument) – Refers to the boolean expression or logical expression that needs to be evaluated.
'value_if_true' (optional argument) – Refers to the value that will be returned by the IF function if the 'logic_test' evaluates to TRUE.
'value_if_false' (optional argument) – Refers to the value that will be returned by the IF function if the 'logic_test' evaluates to FALSE.

Excel If Formula Animation

Important Characteristics of IF Function in Excel

  • To use the IF function, you need to provide the 'logic_test' or conditional statement mandatorily.
  • The arguments 'value_if_true'and 'value_if_false' are optional, but you need to provide at least one of them.
  • The result of the IF statement can only be any one of the two given values (either it will be 'value_if_true' or 'value_if_false'). Both values cannot be returned at the same time.
  • IF function throws a ‘#Name?’ error if the'logic_test' or boolean expression you are trying to evaluate is invalid.
  •  Nesting of IF statements is possible, but Excel only allows this to 64 levels. Nesting of IF statement means using one if statement within another.

Comparison Operators That Can Be Used With IF Statements

Following comparison operators can be used within the 'logic_test' argument of the IF function:

  • = (equal to)
  • <> (not equal to)
  • < (less than)
  • > (greater than)
  • >= (greater than or equal to)
  • <= (less than or equal to)
  • Apart from these, you can also use any other function that returns a boolean result (either ‘true’ or ‘false’). For example – ISBLANK, ISERROR, ISEVEN, ISODD, etc

Now, let’s see some simple examples to use these comparison operators within the IF Function:

Simple Examples of Excel IF Statement

Now, let’s try to see a simple example of the Excel IF function:

Example 1: Using ‘equal to’ comparison operator within the IF function

In this example, we have a list of colors, and we aim to find the ‘Blue’ color. If we are able to find the ‘Blue’ color, then in the adjacent cell, we need to assign a ‘Yes’; otherwise, assign a ‘No’.

if statement excel with equal to operator

So, the formula would be:

=IF(A2="Blue", "No", "Yes")

This suggests that if the value present in cell A2 is ‘Blue’, then return a ‘Yes’; otherwise, return a ‘No’.

If we drag this formula down to all the rows, we will find that it returns ‘Yes’ for the cells with the value ‘Blue’ for all others; it would result in ‘No’.

Example 2: Using ‘not equal to’ comparison operator within the IF function.

Let’s take example 1, and understand how we can reverse the logic and use a ‘not equal to’ operator to construct the formula so that it still results in ‘Yes’ for ‘Blue’ color and ‘No’ for any other text.

if formula in excel with not equal to operator

So the formula would be:

=IF(A2<>"Blue", "No", "Yes")

This suggests that if the value at A2 is not equal to ‘Blue’, then return a ‘No’; otherwise, return a ‘Yes’.

When dragged down to all the below rows, this formula would find all the cells (from A2 to A8) where the value is not ‘Blue’ and marks a ‘No’ against them. Otherwise, it marks a ‘Yes’ in the adjacent cells.

Example 3: Using ‘less than’ operator within the IF function.

In this example, we have scores of some students, along with their names. We want to assign either «Pass» or «Fail» against each student in the result column.

if function excel with less than operator

Based on our criteria, the passing score is 50 or more.

For this, we can use the IF function as:

=IF(B2<50,"Fail","Pass")

This suggests that if the value at B2, i.e., 37, is less than 50, then return «Fail»; otherwise, return «Pass».

As 37 is less than 50 so the result will be «Fail».

We can drag the above-given formula for the rest of the cells below and the result would be correct.

Example 4: Using ‘greater than or equal to’ operator within the IF statement.

Let’s take example 3 and see how we can reverse the logic and use a ‘greater than or equal to’ operator to construct the formula so that it still results in ‘Pass’ for scores of 50 or more and ‘Fail’ for all the other scores.

how to use if function in excel with greater than equal to operator

For this, we can use the Excel IF function as:

=IF(B2>=50,"Pass","Fail")

This suggests that if the value at B2, i.e., 37 is greater than or equal to 50, then return «Pass»; otherwise, return «Fail».

As 37 not greater than or equal to 50 so the result will be «Fail».

When dragged down for the rest of the cells below, this formula would assign the correct result in the adjacent rows.

Example 5: Using ‘greater than’ operator within the IF statement.

In this example, we have a small online store that gives a discount to its customers based on the amount they spend. If a customer spends $50 or more, he is applicable for a 5% discount; otherwise, no discounts are offered.

using if function in excel with greater than operator

To find whether a discount is offered or not, we can use the following excel formula:

=IF(B2>50,"5% Discount","No Discount")

This translates to – If the value at B2 cell is greater than 50, assign a text «5% Discount» otherwise, assign a text «No Discount» against the customer.

In the first case, as 23 is not greater than 50, the output will be «No Discount».

We can drag the above-given formula for the rest of the cells below are the result would be correct.

Example 6: Using ‘less than or equal to’ operator within the IF statement.

Let’s take example 5 and see how we can reverse the logic and use a ‘less than or equal to’ operator to construct the formula so that it still results in a ‘5% Discount’ for all customers whose total spend exceeds $50 and ‘No Discount’ for all the other customers.

excel if else formula with less than equal to operator

For this, we can use the IF-then statement as:

=IF(B2<=50,"No Discount","5% Discount")

This means that if the value at B2, i.e., 23, is less than or equal to 50, then return «No Discount»; otherwise, return «5% Discount».

As 23 is less than or equal to 50 so the result will be «No Discount».

When dragged down for the rest of the cells below, this formula would assign the correct result in the adjacent rows.

Example 7: Using an Excel Logical Function within the IF formula in Excel.

In this example, let’s suppose we have a list of numbers, and we have to mark Even and Odd numbers. We can do this using the IF condition and the ISEVEN or ISODD inbuilt functions provided by Microsoft Excel.

ISEVEN function returns ‘true’ if the number passed to it is even; otherwise, it returns a ‘false’. Similarly, ISODD function return ‘true’ if the number passed to it is odd; otherwise, it returns a ‘false’.

how to do if statements in excel with another function as logic test

For this, we can use the IF-then statement as:

=IF(ISEVEN(A2),"Even","Odd")

This means that – If the value at A2 cell is an even number, then the result would be «Even»; otherwise, the result would be «Odd».

Alternatively, the above logic can also be written using the ISODD function along with the IF statement as:

=IF(ISODD(A2),"Odd","Even")

This means that – If the value at A2 cell is an odd number, then the result would be «Odd»; otherwise, the result would be «Even».

Example 8: Using the Excel IF function to return another formula a result.

In this example, we have Employee Data from a company. The company comes up with a simple way to reward its loyal employees. They decide to give the employees an annual bonus based on the years spent by the employee within the organization.

Employees with experience of more than 5 years are given 10% of annual salary as a bonus whereas everyone else gets a 5% of annual salary as a bonus.

Excel IF function to return another formula a result

For this, the excel formula would be:

=IF(B2>5,C2*10%,C2*5%)

This means that – if the value at B2 (experience column) is greater than 5, then return a result by calculating 10% of C2 (annual salary column). However, if the logic test is evaluated to false, then return the result by calculating 5% of C2 (annual salary column)

Use Of AND & OR Functions or Logical Operators with Excel IF Statement

Excel IF Statement can also be used along with the other functions like AND, OR, NOT for analyzing complex logic. These functions (AND, OR & NOT) are called logical operators as they are used for connecting two or more logical expressions.

AND Function– AND function returns true when all the conditions inside the AND function evaluate to true. The syntax of AND Function in Excel is:

=AND(Logic1, Logic2, logic_n)

OR Function– OR function returns true when any one of the conditions inside the OR function evaluates to true. The syntax of OR Function in Excel is:

=OR(Logic1, Logic2, logic_n)

Example 9: Using the IF function along with AND Function.

In this example, we have Math and science test scores of some students, and we want to assign a ‘Pass’ or ‘Fail’ value against the students based on their scores.

Passing criteria: Students have to get more than 50 marks in Math and more than 70 marks in science to pass the test.

if and statement excel

Based on the above conditions, the formula would be:

=IF(AND(B2>50,C2>70),"Pass","Fail")

The formula translates to – if the value at B2 (Math score) is greater than 50 and the value at C2 (Science Score) is greater than 70, then assign the value «Pass»; otherwise, assign the value «Fail».

Example 10: Using the IF function along with OR Function.

In this example, we have two test scores of some students, and we want to assign a ‘Pass’ or ‘Fail’ value against the students based on their scores.

Passing criteria: Students have to clear either one of the two tests with more than 50 marks.

if or statement excel

Based on the above conditions, the formula would be:

=IF(OR(B2>50,C2>50),"Pass","Fail")

The formula translates to – if either the value at B2 (Test 1 score) is greater than 50, OR the value at C2 (Test 2 Score) is greater than 50, then assign the value «Pass»; otherwise, assign the value «Fail».

Recommended Reading: Excel NOT Function

Nested IF Statements

When used alone, IF formula can only result in two outcomes, i.e., True or False. But there are many cases when we want to test multiple outcomes with IF statement.

In such cases, nesting two or more IF Then statements one inside another can be convenient in writing formulas.

Syntax:

The syntax of the Nested IF Then statements is as follows:

=IF(condition_1,value_if_true_1,IF(condition_2,value_if_true_2,value_if_false_2))

'condition_1' – Refers to the first logical test or conditional expression that needs to be evaluated by the outer IF function.
'value_if_true_1' – Refers to the value that will be returned by the outer IF function if the 'condition_1' evaluates to TRUE.
'condition_2' – Refers to the second logical test or conditional expression that needs to be evaluated by the inner IF function.
'value_if_true_2' – Refers to the value that will be returned by the inner IF function if the 'condition_2' evaluates to TRUE.
'value_if_false_2' – Refers to the value that will be returned by the inner IF function if the 'condition_2' evaluates to FALSE.

The above syntax translates to this:

IF Condition1 = true THEN value_if_true1 'If Condition1 is true
ELSE IF Condition2 = true THEN value_if_true2 'Elseif Clause Condition2 is true
ELSE value_if_false2 'If both conditions are false
END IF 'End of IF Statement

As we can see, Nested formulas can quickly become complicated so, let’s try to understand how nesting of the IF statement works with an example.

Recommended Reading: VBA Select Case Statement

Example 11: Nested IF Statements

In this example, we have a list of countries and their average temperatures in degree Celsius for the month of January. Our goal is to categorize the country based on the temperature range as follows:

Criteria: Temperatures below 20 °C should be marked as «Below Room Temperature», temperatures between 20°C to 25°C should be classified as «Normal Room Temperature», whereas any temperature over 25°C should be marked as «Above Room Temperature».

nested if statements excel

Based on the above conditions, the formula would be:

=IF(B2<20,"Below Room Temperature",IF(AND(B2>=20,B2<=25),"Normal Room Temperature", "Above Room Temperature"))

The formula translates to – if the value at B2 is less than 20, then the text «Below Room Temperature» is returned from the outer IF block. However, if the value at B2 is greater than or equal to 20, then the inner IF block is evaluated.

Inside the inner IF block, the value at B2 is checked. If the value at B2 is greater than or equal to 20 and less than or equal to 25. Then the inner IF block returns the text «Normal Room Temperature».

However, if the condition inside the inner IF block also evaluates to ‘false’ that means the value at B2 is greater than 25, so the result will be «Above Room Temperature».

Recommended Reading: SWITCH Function in Excel

Partial Matching or Wildcards with IF Function

Although IF function itself doesn’t accept any wildcard characters like (* or ?) while performing the logic test, thankfully, there are ways to perform partial matching and wildcard searches with the IF function.

To perform partial matching inside the IF function, we can use the FIND (case sensitive) or SEARCH (case insensitive) functions.

Let’s have a look at this with some examples.

Example 12: Using FIND and SEARCH functions inside the IF statement

In this example, we have a list of customers, and we need to find all the customers whose last name is «Flynn». If the customer name contains the text «Flynn», then we need to assign a text «Found» against their names. Otherwise, we need to assign a text «Not Found».

if function with find and search functions

For this, we can make use of the FIND function within the IF function as:

=IF(ISNUMBER(FIND("Flynn",A2)),"Found","Not Found")

Using the FIND function, we perform a case-sensitive search of the text «Flynn» within the customer name column. If the FIND function is able to find the text «Flynn», it returns a number signifying the position where it found the text.

If the number returned by the FIND function is valid, the ISNUMBER Function returns a value true. Else, it returns false. Based on the ISNUMBER function’s output, the logic test is performed and the appropriate value «Found» or «Not Found» is assigned.

Note: It should be noted that the FIND function performs a case-sensitive search.

This means in the above example if the customer name is entered in lower case (like «sean flynn» then the above function would return not found against them.

To perform a case-insensitive search, we can replace the find function with the search function, and the rest of the formula would be the same.

=IF(ISNUMBER(SEARCH("Flynn",A2)),"Found","Not Found")

Example 13: Using SEARCH function inside the Excel IF formula with wildcard operators

In this example, we have the same customer list from example 12, and we need to find all the customers whose name contains «M». If the customer name contains the alphabet «M», we need to assign a text «M Found» against their names. Otherwise, we need to assign a text «M Not Found».

If Formula search with Wildcard characters or pattern matching

For this, we can use the SEARCH function with a wildcard ‘*’ operator inside the IF function as:

=IF(ISNUMBER(SEARCH("M*",A2)),"M Found","M Not Found")

For more details on Search Function and wildcard, operators check out this article – Search Function In Excel

Some Practical Examples of using the IF function

Now, let’s have a look at some more practical examples of the Excel IF Function.

Example 14: Using Excel IF function with dates.

In this example, we have a task list along with the task due dates. Our goal is to show results based on the task due date.

If the task due date was in the past, we need to show «Was due {1,2,3..} day(s) back», if the task due date is today’s date, we need to show «Today» and similarly, if the task due date is in the future then we need to show «Due in {1,2,3..} day(s)»

If Formula in Excel with Dates
In Microsoft Excel, we can do this with the help of the IF-then statement and TODAY function, as shown below:

=IF(B2=TODAY(),"Today", IF(B2>TODAY(),CONCAT("Due in ",B2-TODAY()," day(s)"), CONCAT("Was due ",TODAY()-B2," day(s) back")))

This means that – compare the date present in cell B2 if the date is equal to today’s date show the text «Today». If the date in cell B2 is not equal to today’s date, then the inner IF block checks if the date in B2 is greater than today’s date. If the date in cell B2 is greater than today’s date, that means the date is in the future, so show the text «Due in {1,2,3…} days».

However, if the date in cell B2 is not greater than today’s date, that means the date was in the past; in such a case, show the text «Was due {1,2,3..} day(s) back».

You can also go a step further and apply conditional formatting on the range and highlight all the cells with the text «Today!». This will help you to clearly see

Example 15: Use an IF function-based formula to find blank cells in excel.

In this example, we will use the IF function to find the blank cells in Microsoft Excel. We have a list of customers, and in between the list, some of the cells are blank. We aim to find the blank cells and add the text «blank call found!» against them.

Find Blank Cells In Excel Using If Function

We can do this with the help of the IF function along with the ISBLANK function. The ISBLANK function returns a true if the cell reference passed to it is blank. Otherwise, the ISBLANK function returns false.

Let’s see the formula –

=IF(ISBLANK(A2), "Blank cell found!"," ")

This means that – If the cell at A2 is blank, then the resultant text should be «Blank cell found!», however, if the cell at A2 is not blank, then don’t show any text.

Example 16: Use the Excel IF statement to show symbolic results (instead of textual results).

In this example, we have a list of sales employees of a company along with the number of products sold by the employees in the current month. We want to show an upward arrow symbol (↑) if the employee has done more than 50 sales and a downward arrow symbol (↓) if the employee has made less than 50 sales.

Showing symbols with If function In excel instead of text

To do this, we can use the formula:

=IF(B2>50,$G$6,$G$8)

This implies – If the value at B2 is greater than 50, then, as a result, show the content in cell G6 (cell containing upward arrow) and otherwise show the content at G8 (cell containing downward arrow)

If you wonder about the ‘$’ signs used in the formula, you can check out this post – Excel Absolute References. These ‘$’ symbols are used for making excel cell references absolute.

Recommended Reading: CHOOSE Function in Excel

IFS Function In Excel:

IFS Function in Microsoft Excel is a great alternative to nested IF Statements. It is very similar to a switch statement. The IFS function evaluates multiple conditions passed to it and returns the value corresponding to the first condition that evaluates to true.

IFS function is a lot simple to write and read than nested IF statements. IFS function is available in Office 2019 and higher versions.

Syntax for IFS function:

=IFS (test1, value1, [test2, value2], ...)

'test1' (required argument) – Refers to the first logical test that needs to be evaluated.

'value1' (required argument) – Refers to the result to be returned when 'test1'evaluates to TRUE.

'test2' (optional argument) – Refers to the second logical test that needs to be evaluated

'value2' (optional argument) – Refers to the result to be returned when 'test2'evaluates to TRUE.

Example 17: Using IFS function in Excel

In this example, we have a list of students, along with their scores, and we need to assign a grade to the students based on the scores.

The grading criteria is as follows – Grade A for a score of 90 or more, Grade B for a score between 80 to 89.99, Grade C for a score between 70 to 79.99, Grade D for a score between 60 to 69.99, Grade E for a score between 60 to 59.99, Grade F for a score lower than 50.

IFS Function Excel Alternative To Nested If Functions

Let’s see how easily write such a complicated formula with the IFS function:

=IFS(B2 >= 90,"A",B2 >= 80,"B",B2 >= 70,"C",B2 >= 60,"D",B2 >= 50,"E",B2 < 50,"F")

This implies that – If B2 is greater than or equal to 90, return A. Else if B2 is greater than or equal to 80, return B. Else if B2 is greater than or equal to 70, return C. Else if B2 is greater than or equal to 60, return D. Else if B2 is greater than or equal to 50, return E. Else if B2 is less than 50, return F.

If you would try to write the same formula using nested IF statements, see how long and complicated it becomes:

=IF(B2 >= 90,"A",IF(B2 >= 80, "B",IF(B2 >= 70, "C",IF(B2 >= 60, "D",IF(B2 >= 50, "E",IF(B2 < 50, "F"))))))

So, this was all about the IF function in excel. If you want to learn more about IF function, I would recommend you to go through this article – VBA IF Statement With Examples

Excel IF Function is another very useful and a lot used logical excel formula which checks for the fulfillment of condition in excel. In this tutorial, we would cover the following points on the IF formula in Excel:

  • What is the use of IF formula in Excel
  • Syntax and Argument
  • Using the IF function with a simple example in Excel
  • Some interesting facts and points about this function
  • Using Nested IF in Excel
  • Other practical use of the excel IF formula
IF Function in Excel

Purpose of IF Function in Excel

As mentioned in the introduction, the =IF() formula is a logical excel function that is used to check a specified condition in Excel and return a particular text/value based on the condition.

Table of Contents

  1. Purpose of IF Function in Excel
  2. Syntax and Arguments of IF Function
  3. Simple Example of Using IF Function in Excel
  4. Do Not Miss These Points
  5. What is Nested IF Function and How to Use with Example
  6. Other Practical Example of IF Function in Excel
  • If the result of the check condition is TRUE, then excel would return a particular text/value.
  • And if the result of check condition is FALSE, then excel returns another specified text/value.

Syntax and Arguments of IF Function

=IF(logical_test, [value_if_true], [value_if_false])

There are three basic arguments of the excel IF formula:

  • logical_test – In this argument, you need to specify the condition to check for TRUE and FALSE. You could either enter the condition manually or as a reference to some other cell/formula.
  • [value_if_true] – This is an optional argument. Excel will return the text/value you specify in this argument, if the logical_test is TRUE.
  • [value_if_false] – This is also an optional argument. Excel will return the text/value you specify in this argument, if the logical_test is FALSE.

Simple Example of Using IF Function in Excel

Let us take one very simple example in excel to understand how the IF formula works in excel.

Suppose in order to pass an examination, a student needs a minimum of 40 marks in a subject. the below image shows the marks obtained by different students in a subject.

Students Marks Sample Data IF Function

In the above example, in order to determine if the student has passed or failed the examination, simply use the following formula:

=IF(B2>=40,”Pass”,”Fail”)

Explanation of the above IF function – The formula first checks the test condition (i.e. if marks in cell B2 is greater than equal to 40). If the condition matches, then excel returns the text ‘Pass’, otherwise it returns ‘Fail’.

IF Function Example Explained

In the above example, we have used the logical operator ‘greater than equal to’ to check for the minimum marks of 40. Below is the list of other excel logical operators-

Logical Mathematical Operators Excel

Now, when you have some basic understanding of how the Excel IF function works, let us learn some important facts and points about the IF formula.

Do Not Miss These Points

  • The second and third arguments of the IF function (i.e. value_if_true and value_if_false) are optional arguments. Therefore, if you do not specify anything in value_if_true, then excel would return 0 if the IF condition is met. Similarly, if you do not enter anything in value_if_false, then excel would return 0 if the IF condition is not met.
Optional argument empty excel IF
  • The IF function argument can also accept another IF function with it to check for more complex conditions in excel. This is called a nested IF function or nested IF formula.
  • You can embed a maximum of 64 IF formula inside a single IF function.

What is Nested IF Function and How to Use with Example

When you check an IF condition inside another IF condition then it is called as nested IF. This means that you can create a formula or function which checks multiple IF conditions in a sequence.

Let us take one simple example how the multiple IF formula works.

For example, if a student gets less than 40 marks, then excel should mention the text ‘Fail’. Otherwise, if marks are greater than equal to 40, then excel should again check if marks are greater than 80. If yes, then it should return ‘Rank Holder’, else simply ‘Pass’.

Nested IF Formula Example

Note that here excel checks for the condition fulfilment in a sequence.

Other Practical Example of IF Function in Excel

The IF excel formula is very useful in finding the commission of the salesperson based on the target achievement or sales.

Using IF Function to Find Commission

There are many other such practical areas where the IF function can be used in excel. In fact, this is the most used excel function.

RELATED POSTS

  • IFS Function in Excel – Check Multiple Conditions

  • NOT Function in Excel – Gives Wrong Logical Value

  • XOR Function in Excel – Usage with Examples

  • ISLOGICAL Function in Excel – Checking for Boolean TRUE/FALSE

  • MIN Function in Excel – Returning Minimum Value

  • What is Excel Conditional Formatting?

Skip to content

Excel Logo

IF Function in Excel

IF Function Excel

IF Function helps to evaluate the logical expression and return the values for both Boolean results. We can specify two values or expressions to return when the logical expression is TRUE or FALSE. Let us see the syntax of IF Function and real-time examples on IF Function for better understanding.

Syntax of IF Function

If Function Evaluate the first argument and resolves the second argument if the first argument returns TRUE, it resolves the third argument if the first argument returns FALSE.

=IF(logical_test,[value_if_true],[value_if_false])

Syntax of IF Function in Excel

=IF(Expression to Evaluate,Expression If True,Expression If False)

Simple Examples of Excel IF Function

Here the simple examples for easily understanding IF Function. Copy these example to any celll in the Excel Sheet and see the result for cleary understanding the IF Function.

Example 1: The following example returns “CORRECT” based the given expression.

=IF(5>2,”CORRECT”,”WRONG”)

returns “CORRECT”

IF Function Checks the first argument (5>2) and it returns TRUE. It will evaluate the second argument (“CORRECT”) as it the condition is True.

If Function

  1. =IF(): Statement to Call Excel IF Function
  2. 5>2: is the logical test if 5 is greater than 2
  3. “CORRECT”: value if the logical test returns TRUE
  4. “WRONG”: value if the logical test returns FALSE

Copy the above example and paste in any Cell, this example IF Function returns “CORRECT”.

Example 2: The following example returns “WRONG” based the given expression.

=IF(25=10,”CORRECT”,”WRONG”)

returns “WRONG”

IF Function Checks the first argument (25=10) and it returns FALSE. It will evaluate the third argument (“WRONG”) as it the condition is False.

  1. =IF(): Statement to Call Excel IF Function
  2. 25=10: is the logical test to check if 25 is equals to 10
  3. “CORRECT”: value if the logical test returns TRUE
  4. “WRONG”: value if the logical test returns FALSE

Copy the above example and paste in any Cell, this example IF Function returns “WRONG”.

Example 3: The following example checks if the given value is even or odd number.

=IF(MOD(25, 2) =0,”Even Number”,”Odd Number”)

returns “Odd Number”

IF Function Checks the first argument [MOD(25, 2) =0] and it returns FALSE. It will evaluate the third argument (“Odd Number”) as it the condition is False.

  1. =IF(): Statement to Call Excel IF Function
  2. MOD(25, 2) =0: is the logical test to check if 25 MOD 2 is equals to 0
  3. “Even Number”: value if the logical test returns TRUE
  4. “Odd Number”: value if the logical test returns FALSE

Copy the above example and paste in any Cell, this example IF Function returns “Odd Number”.

Excel IF Function – Practical Examples:

Here are the practical examples of IF Function. IF function is on of the most commonly used Excel Function to check the logical test and nested IF Functions. We can combine the IF Function with Other Excel Function to build the complex expressions and formulas.

IF Function to Compare This Year and Last Year Values:

The following Example shows how to compare the sales values of Current Year and Last Year. We have provide Deparment wise data in the sheet with This Year Data in Column B and This Year Data in Collumn C. And logical test is performed in Column D to check if the Column C values are greater the Column B Values.

If Function to Compare This Year and Last Year Values

=IF(C2>B2,”PROFIT”,”LOSS”)

IF Function to compare the values in two columns.

You can copy this formula and paste in the Cell D2 and double click to fill the data range.

  1. =IF(): Statement to Call Excel IF Function
  2. C2>B2: is the logical test to check if 25 MOD 2 is equals to 0
  3. “Profit”: value if the logical test returns TRUE
  4. “Loss”: value if the logical test returns FALSE

If Function to Compare Sum of the Column Values

The following IF Formula compare the Sum of Two Columns in Excel Sheet. This will check if Sum of Column C (Range C2:C12) values are greater than Sumn of Column B (Range B2:B12).

=IF(SUM(C2:C11)>SUM(B2:B11),”Profit”,”Loss”)

IF function to compare sum of two ranges in Excel.

  1. =IF(): Statement to Call Excel IF Function
  2. SUM(C2:C11)>SUM(B2:B11): is the logical test to check if 25 MOD 2 is equals to 0
  3. “Profit”: value if the logical test returns TRUE
  4. “Loss”: value if the logical test returns FALSE

If in Excel have verity of forms and applications. We can use IF formula to check the Boolean condition. We can return some value if the condition is true and some other value if not true or false. Let us see the in-depth details about If in Excel.

If Formula in Excel

We can use the If formula in Excel to check if a condition is meeting certain scenario. For example, we can check if the given value is equals to an integer. We can use If formula to compare two strings. We can return the values based on the Boolean result of If formula in Excel. The following example check if the given value is greater than 10 or not. And return the message based on the result.

=If(25>10,"Given Value is bigger than 10","Given Values is Not Bigger Than 10")

If Formula to check Cell Values

We can check the cell value using If formula and perform the calculations based on the result. Here is a simple example in Cell B1 to check if a cell (A1) is less than or equals to 1000 or not. And add 500 if the values is less than 1000.

If Cell Value is Less Than

=IF(A1<1000,A1+500,A1)

If formula checks the condition (A1<1000) and add 500 if the cell value is less than 1000,  it will return the same value if the condition fails.

If Formula to check all values in a Column

We can check the values in a column and perform certain calculation based on the result. Let us see an example to check if any value in column B is equals to zero and flag the respective cell in Column C.

If Formula to check all values in a Column

=IF(B1=0,"Zero","")

You can put this formula in C1 and fill-down upto rows of B1.

Share This Story, Choose Your Platform!

4 Comments

  1. Greg
    October 29, 2019 at 9:21 am — Reply

    Thank you for this easy to understand tutorial on Excel If function. I can say that this is the best way and simple approach to learn IF formula with strong understanding of fundamentals of Excel IF function.

  2. Anna
    October 29, 2019 at 9:27 am — Reply

    Yes, agree with you!
    I am completely impressed with the way of explaining the If function with suitable and real-time examples.

    Excellent! Good Job!! Keep it Up!

  3. Jose Valle
    June 22, 2022 at 8:58 pm — Reply

    how can I make this formula work =MOD(E2-B2-D2+C2,1)*24,IF(G2=”Yes”,F2+0.5,IF(G2=”No”,$F$2)) what I’m I missing or need to do

    • PNRao
      July 1, 2022 at 2:50 am — Reply

      Comma(,) following number 24. Please describe your question in detailed. Just to inform you, the Mod Value with divisor 1 always return 0.

© Copyright 2012 – 2020 | Excelx.com | All Rights Reserved

Page load link

Normally, If you want to write an IF formula for text values in combining with the below two logical operators in excel, such as: “equal to” or “not equal to”.

Table of Contents

  • Excel IF function check if a cell contains text(case-insensitive)
  • Excel IF function check if a cell contains text (case-sensitive)
  • Excel IF function check if part of cell matches specific text
  •  Excel IF function with Wildcards text value
    • Related Formulas
    • Related Functions

Excel IF function check if a cell contains text(case-insensitive)

By default, IF function is case-insensitive in excel. It means that the logical text for text values will do not recognize case in the IF formulas. For example, the following two IF formulas will get the same results when checking the text values in cells.

=IF(B1="excel","yes","no")
=IF(B1="EXCEl","yes","no")

The IF formula will check the values of cell B1 if it is equal to “excel” word, If it is TRUE, then return “yes”, otherwise return “no”. And the logical test in the above IF formula will check the text values in the logical_test argument, whatever the logical_test values are “Excel”, “eXcel”, or “EXCEL”, the IF formula don’t care about that if the text values is in lowercase or uppercase, It will get the same results at last.

Excel IF function check if a cell contains text1

Excel IF function check if a cell contains text1

Excel IF function check if a cell contains text (case-sensitive)

If you want to check text values in cells using IF formula in excel (case-sensitive), then you need to create a case-sensitive logical test and then you can use IF function in combination with EXACT function to compare two text values. So if those two text values are exactly the same, then return TRUE. Otherwise return FALSE.

So we can write down the following IF formula combining with EXACT function:

=IF(EXACT(B1,"excel"),"yes","no")

Excel IF function check if a cell contains text case-sensitive1

Excel IF function check if part of cell matches specific text

If you want to check if part of text values in cell matches the specific text rather than exact match, to achieve this logic text, you can use IF function in combination with ISNUMBER and SEARCH Function in excel.

Both ISNUMBER and SEARCH functions are case-insensitive in excel.

=IF(ISNUMBER(SEARCH("x",B1)),"good","bad")

Excel IF function check if part of cell matches specific text1

For above the IF formula, it will Check to see if B1 contain the letter x.

Also, we can use FIND function to replace the SEARCH function in the above IF formula. It will return the same results.

 Excel IF function with Wildcards text value

If you wan to use wildcard charcter in an IF formula, for example, if any of the values in column B contains “*xc*”, then return “good”, others return “bad”. You can not directly use the wildcard characters in IF formula, and we can use IF function in combination with COUNTIF function. Let’s see the following IF formula:

=IF(COUNTIF(B1:B4,"*xc*"), "good","bad")

Excel IF function with Wildcards text value1


  • Excel IF Function With Numbers
    If you want to check if a cell values is between two values or checking for the range of numbers or multiple values in cells, at this time, we need to use AND or OR logical function in combination with the logical operator and IF function…

  • Excel EXACT function
    The Excel SEARCH function returns the number of the starting location of a substring in a text string.The syntax of the EXACT function is as below:= EXACT (text1,text2)…
  • Excel COUNTIF function
    The Excel COUNTIF function will count the number of cells in a range that meet a given criteria.= COUNTIF (range, criteria) …
  • Excel ISNUMBER function
    The Excel ISNUMBER function returns TRUE if the value in a cell is a numeric value, otherwise it will return FALSE.
  • Excel IF function
    The Excel IF function perform a logical test to return one value if the condition is TRUE and return another value if the condition is FALSE….
  • Excel SEARCH function
    The Excel SEARCH function returns the number of the starting location of a substring in a text string.…

Simple If Examples | And/Or Criteria | Nested If | More about If

The IF function is one of the most used functions in Excel. This page contains many easy to follow IF examples.

Simple If Examples

The IF function checks whether a condition is met, and returns one value if true and another value if false.

1a. For example, take a look at the IF function in cell B2 below.

If Greater Than

Explanation: if the price is greater than 500, the IF function returns High, else it returns Low.

1b. The following IF function produces the exact same result.

If Less Than

Note: you can use the following comparison operators: = (equal to), > (greater than), < (less than), >= (greater than or equal to), <= (less than or equal to) and <> (not equal to).

2. Always enclose text in double quotation marks.

Simple IF function in Excel

3a. The formula below calculates the progress between two points in time.

Calculate Progress

3b. You can use the IF function to display an empty string if the end value hasn’t been entered yet (see row 5).

Display Empty String

Explanation: if the end value is not empty (<> means not equal to), the IF function calculates the progress between the start and end value, else it displays an empty string (two double quotes with nothing in between).

And/Or Criteria

Use the IF function in combination with the AND function and the OR function and become an Excel expert.

1. For example, take a look at the IF function in cell D2 below.

If this And that

Explanation: the AND function returns TRUE if the first score is greater than or equal to 60 and the second score is greater than or equal to 90, else it returns FALSE. If TRUE, the IF function returns Pass, if FALSE, the IF function returns Fail.

2. For example, take a look at the IF function in cell D2 below.

If this Or that

Explanation: the OR function returns TRUE if at least one score is greater than or equal to 60, else it returns FALSE. If TRUE, the IF function returns Pass, if FALSE, the IF function returns Fail.

3. For example, take a look at the IF function in cell D2 below.

Advanced IF function

Explanation: the AND function above has two arguments separated by a comma (Table, Green or Blue). The AND function returns TRUE if Product equals «Table» and Color equals «Green» or «Blue». If TRUE, the IF function reduces the price by 50%, if FALSE, the IF function reduces the price by 10%.

Nested If

The IF function in Excel can be nested, when you have multiple conditions to meet. The FALSE value is being replaced by another IF function to make a further test.

1. For example, take a look at the nested IF formula in cell C2 below.

Nested IF example

Explanation: if the score equals 1, the nested IF formula returns Bad, if the score equals 2, the nested IF formula returns Good, if the score equals 3, the nested IF formula returns Excellent, else it returns Not Valid. If you have Excel 2016 or later, simply use the IFS function.

2. For example, take a look at the nested IF formula in cell C2 below.

Nested IF formula

Explanation: if the score is less than 60, the nested IF formula returns F, if the score is greater than or equal to 60 and less than 70, the formula returns D, if the score is greater than or equal to 70 and less than 80, the formula returns C, if the score is greater than or equal to 80 and less than 90, the formula returns B, else it returns A.

More about If

The IF function is a great function. Let’s take a look at a few more cool examples.

1. For example, use IF and AND to test if a value is between two numbers.

If Value is Between Two Numbers

Explanation: the AND function returns TRUE if the person is older than 12 and younger than 20, else it returns FALSE. If TRUE, the IF function returns Yes, if FALSE, the IF function returns No.

2. You can combine IF with AVERAGE, SUM and other Excel functions. The sky is the limit!

IF, AVERAGE and SUM

Explanation: the AND function returns TRUE if the input value is greater than 100 and the average of the values in the named range Data1 is greater than 100, else it returns FALSE. If TRUE, the IF function returns the sum of Data2, if FALSE, the IF function returns 0.

Confused? You can always use the Evaluate Formula tool to step through your IF formula. This Excel tool helps you understand a formula.

3. For example, select cell G3 above.

4. On the Formulas tab, in the Formula Auditing group, click Evaluate Formula.

Evaluate Formula

5. Click Evaluate multiple times.

Evaluate IF formula

Note: try it yourself. Download the Excel file and choose one of the IF formulas explained on this page. You can use this tool to step through all kinds of formulas.

Понравилась статья? Поделить с друзьями:
  • Check the spelling of the word
  • Check the sentence with the bolded word that makes better sense
  • Check if excel is open vba
  • Check the pronunciation of a word
  • Check if excel contains text