If condition with text 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?

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.…

The logical IF statement in Excel is used for the recording of certain conditions. It compares the number and / or text, function, etc. of the formula when the values correspond to the set parameters, and then there is one record, when do not respond — another.

Logic functions — it is a very simple and effective tool that is often used in practice. Let us consider it in details by examples.



The syntax of the function «IF» with one condition

The operation syntax in Excel is the structure of the functions necessary for its operation data.

=IF(boolean;value_if_TRUE;value_if_FALSE)

Let us consider the function syntax:

  • Boolean – what the operator checks (text or numeric data cell).
  • Value_if_TRUE – what will appear in the cell when the text or numbers correspond to a predetermined condition (true).
  • Value_if_FALSE – what appears in the box when the text or the number does not meet the predetermined condition (false).

Example:

Example.

Logical IF functions.

The operator checks the A1 cell and compares it to 20. This is a «Boolean». When the contents of the column is more than 20, there is a true legend «greater 20». In the other case it’s «less or equal 20».

Attention! The words in the formula need to be quoted. For Excel to understand that you want to display text values.

Here is one more example. To gain admission to the exam, a group of students must successfully pass a test. The results are listed in a table with columns: a list of students, a credit, an exam.

list.

The statement IF should check not the digital data type but the text. Therefore, we prescribed in the formula В2= «done» We take the quotes for the program to recognize the text correctly.



The function IF in Excel with multiple conditions

Usually one condition for the logic function is not enough. If you need to consider several options for decision-making, spread operators’ IF into each other. Thus, we get several functions IF in Excel.

The syntax is as follows:

Here the operator checks the two parameters. If the first condition is true, the formula returns the first argument is the truth. False — the operator checks the second condition.

Examples of a few conditions of the function IF in Excel:

few conditions.

It’s a table for the analysis of the progress. The student received 5 points:

  • А – excellent;
  • В – above average or superior work;
  • C – satisfactory;
  • D – a passing grade;
  • E – completely unsatisfactory.

IF statement checks two conditions: the equality of value in the cells.

two conditions.

In this example, we have added a third condition, which implies the presence of another report card and «twos». The principle of the operator is the same.

Enhanced functionality with the help of the operators «AND» and «OR»

When you need to check out a few of the true conditions you use the function И. The point is: IF A = 1 AND A = 2 THEN meaning в ELSE meaning с.

OR function checks the condition 1 or condition 2. As soon as at least one condition is true, the result is true. The point is: IF A = 1 OR A = 2 THEN value B ELSE value C.

Functions AND & OR can check up to 30 conditions.

An example of using the operator AND:

operator AND.

It’s the example of using the logical operator OR.

example of using OR.

How to compare data in two tables

Users often need to compare the two spreadsheets in an Excel to match. Examples of the «life»: compare the prices of goods in different bringing, to compare balances (accounting reports) in a few months, the progress of pupils (students) of different classes, in different quarters, etc.

To compare the two tables in Excel, you can use the COUNTIFS statement. Consider the order of application functions.

For example, consider the two tables with the specifications of various food processors. We planned allocation of color differences. This problem in Excel solves the conditional formatting.

Baseline data (tables, which will work with):

tables.

Select the first table. Conditional Formatting — create a rule — use a formula to determine the formatted cells:

formatted cells.

In the formula bar write: = COUNTIFS (comparable range; first cell of first table)=0. Comparing range is in the second table.

To drive the formula into the range, just select it first cell and the last. «= 0» means the search for the exact command (not approximate) values.

Choose the format and establish what changes in the cell formula in compliance. It’s better to do a color fill.

Select the second table. Conditional Formatting — create a rule — use the formula. Use the same operator (COUNTIFS). For the second table formula:

Download all examples in Excel

compare the characteristics.

Now it is easy to compare the characteristics of the data in the table.

Содержание

  1. Create conditional formulas
  2. What do you want to do?
  3. Create a conditional formula that results in a logical value (TRUE or FALSE)
  4. Example
  5. Create a conditional formula that results in another calculation or in values other than TRUE or FALSE
  6. Example
  7. IF Function
  8. Related functions
  9. Summary
  10. Purpose
  11. Return value
  12. Arguments
  13. Syntax
  14. Usage notes
  15. Syntax
  16. Logical tests
  17. IF cell contains specific text
  18. IF function
  19. Simple IF examples
  20. Common problems
  21. Need more help?
  22. IF function
  23. Simple IF examples
  24. Common problems
  25. Need more help?

Create conditional formulas

Testing whether conditions are true or false and making logical comparisons between expressions are common to many tasks. You can use the AND, OR, NOT, and IF functions to create conditional formulas.

For example, the IF function uses the following arguments.

Formula that uses the IF function

logical_test: The condition that you want to check.

value_if_true: The value to return if the condition is True.

value_if_false: The value to return if the condition is False.

For more information about how to create formulas, see Create or delete a formula.

What do you want to do?

Create a conditional formula that results in a logical value (TRUE or FALSE)

To do this task, use the AND, OR, and NOT functions and operators as shown in the following example.

Example

The example may be easier to understand if you copy it to a blank worksheet.

How do I copy an example?

Select the example in this article.

Selecting an example from Help

In Excel, create a blank workbook or worksheet.

In the worksheet, select cell A1, and press CTRL+V.

Important: For the example to work properly, you must paste it into cell A1 of the worksheet.

To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.

After you copy the example to a blank worksheet, you can adapt it to suit your needs.

Determines if the value in cell A2 is greater than the value in A3 and also if the value in A2 is less than the value in A4. (FALSE)

Determines if the value in cell A2 is greater than the value in A3 or if the value in A2 is less than the value in A4. (TRUE)

Determines if the sum of the values in cells A2 and A3 is not equal to 24. (FALSE)

Determines if the value in cell A5 is not equal to «Sprockets.» (FALSE)

Determines if the value in cell A5 is not equal to «Sprockets» or if the value in A6 is equal to «Widgets.» (TRUE)

For more information about how to use these functions, see AND function, OR function, and NOT function.

Create a conditional formula that results in another calculation or in values other than TRUE or FALSE

To do this task, use the IF, AND, and OR functions and operators as shown in the following example.

Example

The example may be easier to understand if you copy it to a blank worksheet.

How do I copy an example?

Select the example in this article.

Important: Do not select the row or column headers.

Selecting an example from Help

In Excel, create a blank workbook or worksheet.

In the worksheet, select cell A1, and press CTRL+V.

Important: For the example to work properly, you must paste it into cell A1 of the worksheet.

To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.

After you copy the example to a blank worksheet, you can adapt it to suit your needs.

=IF(A2=15, «OK», «Not OK»)

If the value in cell A2 equals 15, return «OK.» Otherwise, return «Not OK.» (OK)

=IF(A2<>15, «OK», «Not OK»)

If the value in cell A2 is not equal to 15, return «OK.» Otherwise, return «Not OK.» (Not OK)

=IF(NOT(A2 «SPROCKETS», «OK», «Not OK»)

If the value in cell A5 is not equal to «SPROCKETS», return «OK.» Otherwise, return «Not OK.» (Not OK)

If the value in cell A2 is greater than the value in A3 and the value in A2 is also less than the value in A4, return «OK.» Otherwise, return «Not OK.» (Not OK)

=IF(AND(A2<>A3, A2<>A4), «OK», «Not OK»)

If the value in cell A2 is not equal to A3 and the value in A2 is also not equal to the value in A4, return «OK.» Otherwise, return «Not OK.» (OK)

If the value in cell A2 is greater than the value in A3 or the value in A2 is less than the value in A4, return «OK.» Otherwise, return «Not OK.» (OK)

=IF(OR(A5<>«Sprockets», A6<>«Widgets»), «OK», «Not OK»)

If the value in cell A5 is not equal to «Sprockets» or the value in A6 is not equal to «Widgets», return «OK.» Otherwise, return «Not OK.» (Not OK)

=IF(OR(A2<>A3, A2<>A4), «OK», «Not OK»)

If the value in cell A2 is not equal to the value in A3 or the value in A2 is not equal to the value in A4, return «OK.» Otherwise, return «Not OK.» (OK)

For more information about how to use these functions, see IF function, AND function, and OR function.

Источник

IF Function

Summary

The Excel IF function runs a logical test and returns one value for a TRUE result, and another for a FALSE result. For example, to «pass» scores above 70: =IF(A1>70,»Pass»,»Fail»). More than one condition can be tested by nesting IF functions. The IF function can be combined with logical functions like AND and OR to extend the logical test.

Purpose

Return value

Arguments

  • logical_test — A value or logical expression that can be evaluated as TRUE or FALSE.
  • value_if_true — [optional] The value to return when logical_test evaluates to TRUE.
  • value_if_false — [optional] The value to return when logical_test evaluates to FALSE.

Syntax

Usage notes

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:

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:

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 «red»
If A1 is less than B1 A1 «»
If A1 is less than current date A1 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:

Translation: if A1 is red or blue, return B1+10, otherwise return 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:

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

Источник

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

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

The condition you want to test.

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

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

Simple IF examples

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

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.

B2,”Over Budget”,”Within Budget”)» loading=»lazy»>

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

B2,C2-B2,»»)» loading=»lazy»>

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

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

What went wrong

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.

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.

Источник

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

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

The condition you want to test.

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

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

Simple IF examples

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

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.

B2,”Over Budget”,”Within Budget”)» loading=»lazy»>

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

B2,C2-B2,»»)» loading=»lazy»>

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

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

What went wrong

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.

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.

Источник

Adblock
detector

Skip to content

How to Use the IF Function in Excel: Step-by-Step (2023)

How to Use the IF Function in Excel: Step-by-Step (2023)

The IF function is going to be one of the most useful functions of Excel you’ll ever come across🤩

Once you know how to write the IF function, you’ll use it almost everywhere. With the IF function, Excel tests a given condition.

And returns one value if the condition turns true and another if it turns false. More details about the IF function with many examples of the same await you in the guide below 👇

So jump straight in and take our free sample workbook along with you to practice better.

How to use the IF function in Excel

The IF function is a logical function of Excel that’ll test a supplied condition. If the condition is true, the IF function would return one value.

And if it is false, it will return another value. And by the way, both these values will be supplied by you. Let’s see this through an example 👩‍🏫

Here we have a list of some people along with their ages.

List of people and their ages

Can we use the IF function to see which of these are of the age of 50? For sure. See here:

  1. Activate a cell.
  2. Write the IF function as below:

= IF (B2=50,

Writing the IF function

For the first argument of the IF function, write in the condition to be tested 👴

We want to test if the age of each person equals 50. Ages are in column B so we have written the logical condition B2=50.

This tells Excel to test if B2 is equal to 50.

Note that we have used a logical operator (=) to specify the condition. You’d need a logical operator to specify any kind of condition.

Kasper Langmann, Microsoft Office Specialist
  1. As the next argument, write the value_if_true as below:

= IF (B2=50, “Equals 50”,

Writing the value_if_true

The value_if_true is the value that Excel would return if the logical condition turned true. It is an optional argument that you can omit ❌

For now, we are setting it to “Equals 50”.

If the value_if_true is omitted, and the logical test turns true, Excel simply returns the Boolean value “TRUE” in its place.

Kasper Langmann, Microsoft Office Specialist
  1. Next, write in the value_if_false as below:

= IF (B2=50, “Equals 50”, “Doesn’t equal 50”)

Writing the value_if_false

The value_if_false is the value that Excel would return if the logical condition turned false. It is also an optional argument that you can omit.

We have set it to ‘Doesn’t Equal 50” 🙈

Do not forget to enclose the value_if_true and value_if_false in double quotation marks. Or else would fail to recognize it as a text.

And your IF function would return the #NAME error 🤯

If the value_if_false is omitted, Excel simply returns the Boolean value “FALSE” in its place.

Kasper Langmann, Microsoft Office Specialist
  1. All good! Hit Enter.
IF function formula returns the results

The IF function evaluates if Cell B2 is equal to 50. And as that’s not the case, we get “Doesn’t equal 50” (the value_if_false) 🚩

  1. Drag and drop the same formula to the whole list.
Formula applied to the whole list

And there you get the results of the IF function for the entire list🥂

Note how Excel has supplied the value if true (Equals 50) for Cell B3 and B6 where the age is 60. Pretty simple that was!

IF and logical operators

You can take the IF function game levels ahead by using it together with logical operators.

For example, using the same dataset as above, can we readily see which people are above 50 👀

  1. Write the IF function as below:

= IF (B2>50,

The logical condition for the IF function

As we want to find the ages that are greater than 50, we are going to define a logical condition using the greater than (>) logical operator.

So we have written the condition as B2>50 (is B2 greater than 50?).

  1. Then write the value_if_true and value_if_false as below:

= IF (B2>50, “Greater than 50”, “Not greater than 50”)

Writing the true and false values

We want Excel to return the text string “Greater than 50” if the age is more than 50.

And if any age is less than 50, we want Excel to return “Not greater than 50” ✈

  1. Press Enter.
IF function returns the results

The IF function evaluates if Cell B2 is greater than 50. And we get the result “Greater than 50” in the very first cell as the age in Cell B2 is 88. (88>50) 👌

  1. Drag and drop the same formula to the whole list.
Formula applied to the whole list

Excel evaluates the whole list, and we have our results ready. You can use logical operators like that to test any logical condition.

Pro Tip!

You can use a total of 6 logical operators to write any logical test in Excel 6️⃣

  • Equal to (=)
  • Greater than (>)
  • Less than (<)
  • Greater than or equal to (>=)
  • Less than or equal to (<=)
  • Not equal to (<>)

Other IF formula examples

We’ve yet not had enough of the IF function – and there’s much more to come. Let’s see some more examples of the IF function below 🚴‍♀️

IF formula example #1

The above two examples show how you can use the IF function with numbers. But what if you want to use it with text?

You can still do that. Look into the data below.

Status of Employee duties

Some employees worked overtime, whereas others did not. Based on the overtime detail, we need to offer incentives to employees 💰

So can we readily see which employees are getting a bonus this time?

  1. Write the IF function as below:

= IF (B2=”Worked Overtime”

Text as the logical condition

As we want to find which employee did overtime, we defined the logical condition B2=” Worked Overtime”.

This way Excel will see if cell B2 contains the text value “Worked Overtime” or not.

Here’s something for you to take note of. As we have specified text in our logical condition this time, we have enclosed it in double quotation marks.

Excel would fail to test a text logical condition if the text portion is not enclosed in quotation marks 📌

Kasper Langmann, Microsoft Office Specialist
  1. Then write the value_if_true and value_in_false as below:

= IF (B2=”Worked Overtime”, “Yes”, “No”)

Writing the true and false values

For any employee who has worked overtime, Excel will return a “Yes” and vice versa.

  1. Hit Enter to run the function 🏃‍♀️
IF function runs the logical test
  1. Drag and drop the same formula to the whole list.
IF statement applied to the whole list

The IF function tests if the cells have the text value “Worked Overtime”. And for all the cells that have this value, the result is a “Yes”. And for the employees who didn’t work overtime, the result is a “No”.

Pro Tip!

Did you note that Cell B5 has the status “WORKED OVERTIME” (uppercase characters)?

However, the IF function still finds the logical test to be true, and we have the value “Yes”.

This tells that the IF function is not case-sensitive 🏆

IF formula example #2

This example is going to be an interesting one. We are going to use the IF function with dates in logical tests.

The image below shows different events scheduled on certain dates 📅

In addition to these events, there is another event planned for 03 March 2023. We will now use the IF function to see if any event clashes with the event on 03 March.

  1. Write the IF function as below:

= IF (B2=DATE(2023,03,03)

as the logical condition

We have written the logical test as B2=DATE(2023,03,03)

Excel would now test if cell B2 contains the date 03-Mar-2022 or not.

Pro Tip!

To write the logical criterion using date, we have used the DATE function that works as follows:

=DATE(year,mm,dd)

It is important to know that the logical functions of Excel cannot recognize dates. They instead consider them as text strings 😅

To use dates in the IF function, you must use the DATE function for Excel to convert the date into an understandable format.

Alternatively, you can convert the date into a serial number and then write the IF function like this:

= IF (B2=44988,

However, to know the serial number for the targeted date (like 44988 for 03 March 2023), you still need to apply the DATE function separately 🤷‍♀️

  1. Then write the value_if_true and value_if_false as below:

= IF (B2=DATE(2023,03,03), “Yes”, “No”)

Writing the true and false values

For events that are scheduled on 03 March 2022, Excel will return a “Yes”.

And if that’s not the case, we will get a clean “No” ❌

Interesting, right? Let’s now run the function to see the final results.

  1. Hit Enter.
IF function evaluates the corresponding value
  1. Drag and drop the same formula to the whole list.
IF formula returns the results

Seems like we would have to miss out on Event 3 and Event 5 🙅‍♂️

That’s it – Now what?

A long way we’ve come. In the guide above, we have seen how to use the basic IF function, IF function with logical operators, and with single and multiple conditions.

With this, you now know all the ins and outs of the IF function of Excel. I hope you enjoyed reading it as much as I enjoyed writing it ✍

If you found the IF function useful, must know that it only makes one function of the great Excel. This giant spreadsheet software has so much more for you to explore.

To become an Excel maestro, you must have a fine grip on Excel functions. Particularly, the key Excel functions like the VLOOKUP, SUMIF, and IF functions.

Don’t know where to start? Enroll in my 30-minute free email course that will take you through these (and many more) functions of Excel.

Frequently asked questions

IF is a logical function of Excel. It tests a given condition to be logically true or false.

It allows users to specify a value to be returned if the supplied condition is true, and a value if it is false.

The IF function then evaluates the condition and returns the relevant value if it proves true or false.

The Excel IF function has the following three articles:

Logical_test (required argument) – this is the logical test to be performed.

Value_if_true (optional argument) – this is the value to be returned if the logical test is true.

Value_if_false (optional argument) – this is the value to be returned if the logical test is false.

The IF function can be used to test more complex scenarios by nesting multiple IF functions together.

For example, you can nest multiple IF functions together as follows:

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

This tells Excel to test the first IF function and return the value_if_true if it is true. And if it is false, test the second (nested) IF function.

To learn this in much more detail (with a handful of examples), read our tutorial on the Nested IF function here!

Kasper Langmann2023-02-23T14:47:57+00:00

Page load link

Like this post? Please share to your friends:
  • If condition in excel cell
  • Idioms with the word numbers
  • If command in excel with and
  • Idioms with the word money
  • If combined with or in excel