If or formula in excel 2013

The IF function allows you to make a logical comparison between a value and what you expect by testing for a condition and returning a result if that condition is True or False.

  • =IF(Something is True, then do something, otherwise do something else)

But what if you need to test multiple conditions, where let’s say all conditions need to be True or False (AND), or only one condition needs to be True or False (OR), or if you want to check if a condition does NOT meet your criteria? All 3 functions can be used on their own, but it’s much more common to see them paired with IF functions.

Use the IF function along with AND, OR and NOT to perform multiple evaluations if conditions are True or False.

Syntax

  • IF(AND()) — IF(AND(logical1, [logical2], …), value_if_true, [value_if_false]))

  • IF(OR()) — IF(OR(logical1, [logical2], …), value_if_true, [value_if_false]))

  • IF(NOT()) — IF(NOT(logical1), value_if_true, [value_if_false]))

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.

Here are overviews of how to structure AND, OR and NOT functions individually. When you combine each one of them with an IF statement, they read like this:

  • AND – =IF(AND(Something is True, Something else is True), Value if True, Value if False)

  • OR – =IF(OR(Something is True, Something else is True), Value if True, Value if False)

  • NOT – =IF(NOT(Something is True), Value if True, Value if False)

Examples

Following are examples of some common nested IF(AND()), IF(OR()) and IF(NOT()) statements. The AND and OR functions can support up to 255 individual conditions, but it’s not good practice to use more than a few because complex, nested formulas can get very difficult to build, test and maintain. The NOT function only takes one condition.

Examples of using IF with AND, OR and NOT to evaluate numeric values and text

Here are the formulas spelled out according to their logic:

Formula

Description

=IF(AND(A2>0,B2<100),TRUE, FALSE)

IF A2 (25) is greater than 0, AND B2 (75) is less than 100, then return TRUE, otherwise return FALSE. In this case both conditions are true, so TRUE is returned.

=IF(AND(A3=»Red»,B3=»Green»),TRUE,FALSE)

If A3 (“Blue”) = “Red”, AND B3 (“Green”) equals “Green” then return TRUE, otherwise return FALSE. In this case only the first condition is true, so FALSE is returned.

=IF(OR(A4>0,B4<50),TRUE, FALSE)

IF A4 (25) is greater than 0, OR B4 (75) is less than 50, then return TRUE, otherwise return FALSE. In this case, only the first condition is TRUE, but since OR only requires one argument to be true the formula returns TRUE.

=IF(OR(A5=»Red»,B5=»Green»),TRUE,FALSE)

IF A5 (“Blue”) equals “Red”, OR B5 (“Green”) equals “Green” then return TRUE, otherwise return FALSE. In this case, the second argument is True, so the formula returns TRUE.

=IF(NOT(A6>50),TRUE,FALSE)

IF A6 (25) is NOT greater than 50, then return TRUE, otherwise return FALSE. In this case 25 is not greater than 50, so the formula returns TRUE.

=IF(NOT(A7=»Red»),TRUE,FALSE)

IF A7 (“Blue”) is NOT equal to “Red”, then return TRUE, otherwise return FALSE.

Note that all of the examples have a closing parenthesis after their respective conditions are entered. The remaining True/False arguments are then left as part of the outer IF statement. You can also substitute Text or Numeric values for the TRUE/FALSE values to be returned in the examples.

Here are some examples of using AND, OR and NOT to evaluate dates.

Examples of using IF with AND, OR and NOT to evaluate dates

Here are the formulas spelled out according to their logic:

Formula

Description

=IF(A2>B2,TRUE,FALSE)

IF A2 is greater than B2, return TRUE, otherwise return FALSE. 03/12/14 is greater than 01/01/14, so the formula returns TRUE.

=IF(AND(A3>B2,A3<C2),TRUE,FALSE)

IF A3 is greater than B2 AND A3 is less than C2, return TRUE, otherwise return FALSE. In this case both arguments are true, so the formula returns TRUE.

=IF(OR(A4>B2,A4<B2+60),TRUE,FALSE)

IF A4 is greater than B2 OR A4 is less than B2 + 60, return TRUE, otherwise return FALSE. In this case the first argument is true, but the second is false. Since OR only needs one of the arguments to be true, the formula returns TRUE. If you use the Evaluate Formula Wizard from the Formula tab you’ll see how Excel evaluates the formula.

=IF(NOT(A5>B2),TRUE,FALSE)

IF A5 is not greater than B2, then return TRUE, otherwise return FALSE. In this case, A5 is greater than B2, so the formula returns FALSE.

Example of the Evaluate Formula Wizard

Using AND, OR and NOT with Conditional Formatting

You can also use AND, OR and NOT to set Conditional Formatting criteria with the formula option. When you do this you can omit the IF function and use AND, OR and NOT on their own.

From the Home tab, click Conditional Formatting > New Rule. Next, select the “Use a formula to determine which cells to format” option, enter your formula and apply the format of your choice.

Conditional Formatting > Edit Rule dialog showing the Formula method

Using the earlier Dates example, here is what the formulas would be.

Example of using AND, OR and NOT as Conditional Formatting tests

Formula

Description

=A2>B2

If A2 is greater than B2, format the cell, otherwise do nothing.

=AND(A3>B2,A3<C2)

If A3 is greater than B2 AND A3 is less than C2, format the cell, otherwise do nothing.

=OR(A4>B2,A4<B2+60)

If A4 is greater than B2 OR A4 is less than B2 plus 60 (days), then format the cell, otherwise do nothing.

=NOT(A5>B2)

If A5 is NOT greater than B2, format the cell, otherwise do nothing. In this case A5 is greater than B2, so the result will return FALSE. If you were to change the formula to =NOT(B2>A5) it would return TRUE and the cell would be formatted.

Note: A common error is to enter your formula into Conditional Formatting without the equals sign (=). If you do this you’ll see that the Conditional Formatting dialog will add the equals sign and quotes to the formula — =»OR(A4>B2,A4<B2+60)», so you’ll need to remove the quotes before the formula will respond properly.

Need more help?

Connect with an expert. Learn from live instructors.​​​​​​​

See also

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

Learn how to use nested functions in a formula

IF function

AND function

OR function

NOT function

Overview of formulas in Excel

How to avoid broken formulas

Detect errors in formulas

Keyboard shortcuts in Excel

Logical functions (reference)

Excel functions (alphabetical)

Excel functions (by category)

Logical functions are designed to test one or several conditions, and perform the actions prescribed for each of the two possible results. Such results can only be logical TRUE or FALSE.

Excel contains several logical functions such as IF, IFERROR, SUMIF, AND, OR, and others. The last two are not used in practice, as a rule, because the result of their calculations may be one of only two possible options (TRUE, FALSE). When combined with the IF function, they are able to significantly expand its functionality.



Examples of using formulas with IF, AND, OR functions in Excel

Example 1. When calculating the cost of the amount of consumed kW of electricity for subscribers, the following conditions are taken into account:

  1. If less than 3 people live in the apartment or less than 100 kW of electricity was consumed per month, the rate per 1 kW is 4.35$.
  2. In other cases, the rate for 1 kW is 5.25$.

Calculate the amount payable per month for several subscribers.

View source data table:

Example 1.

Perform the calculation according to the formula:

Argument Description:

  • OR (B3<=2,C3<100) is a logical expression that verifies two conditions: do less than 3 people live in the apartment or does the total amount of energy consumed less than 100 kW? The result of the test will be TRUE if either of these two conditions is true;
  • C3 * 4.35 — the amount to be paid, if the OR function returns TRUE;
  • C3 * 5.25 is the amount to be paid if OR returns FALSE.

We stretch the formula for the remaining cells using the autocomplete function. The result of the calculation for each subscriber:

several logical functions.

Using the AND function in the formula in the first argument in the IF function, we check the conformity of the values by two conditions at once.



Formula with IF and AVERAGE functions for selecting of values by conditions

Example 2. Applicants entering the university for the specialty «mechanical engineer» are required to pass 3 exams in mathematics, physics and English. The maximum score for each exam is 100. The average passing score for 3 exams is 75, while the minimum score in physics must be at least 70 points, and in mathematics it is 80. Determine applicants who have successfully passed the exams.

View source table:

Example 2.

To determine the enrolled students use the formula:

Argument Description:

  • AND(B4>=80,C4>=70,AVERAGE(B4:D4)>=75) — checked logical expressions according to the condition of the problem;
  • «Enroll» — the result, if the function AND returned the value TRUE (all expressions represented as its arguments, as a result of the calculations returned the value TRUE);
  • «Not Enroll» — the result if AND returned FALSE.

Using the autocomplete function (double-click on the cursor marker in the lower right corner), we get the rest of the results:

Formula with IF and AVERAGE.

Formula with logical functions AND IF OR in excel

Example 3. Subsidies in the amount of 30% are charged to families with an average income below 8,000$, which are large or there is no main breadwinner. If the number of children is over 5, the amount of the subsidy is 50%. Determine who should receive subsidies and who should not.

View source table:

Example 3.

To check the criteria according to the condition of the problem, we write the formula:

Argument Description:

  • AND(B3<8000,OR(C3=TRUE,E3=FALSE)) is the checked expression according to the condition of the problem. In this case, the AND function returns the TRUE value, if B3 <8000 is true and at least one of the expressions passed as arguments to the OR function also returns the TRUE value.
  • The nested IF function performs a check on the number of children in the family, which rely on subsidies.
  • If the main condition returned the result is FALSE, the main function IF returns the text string “no”.

Perform the calculation for the first family and stretch the formula to the remaining cells using the autocomplete function. Results:

functions AND IF OR.

Features of using logical functions IF, AND, OR in Excel

The IF function has the following syntax notation:

=IF(Logical_test,[ Value_if_True ],[ Value_if_False])

As you can see, by default, you can check only one condition, for example, is e3 more than 20? Using the IF function, this check can be done as follows:

=IF(EXP(3)>20,»more»,»less»)

As a result, the text string “more” will be returned. If we need to find out if any value belongs to the specified interval, we will need to compare this value with the upper and lower limits of the intervals, respectively. For example, is the result of calculating e3 in the range from 20 to 25? When using the IF function alone, you must enter the following entry:

=IF(EXP(3)>20,IF(EXP(3)<25,»belongs»,»does not belong»),»does not belong»)

We have a nested function IF as one of the possible results of the implementation of the main function IF, and therefore the syntax looks somewhat cumbersome. If you also need to know, for example, whether the square root e3 is equal to a numeric value from a fractional number range from 4 to 5, the final formula will look cumbersome and unreadable.

It is much easier to use as a condition a complex expression that can be written using AND and OR functions. For example, the above function can be rewritten as follows:

=IF(AND(EXP(3)>20,EXP(3)<25),»belongs»,»does not belong»)

The result of the execution of the AND expression (EXP(3)>20,EXP(3)<25) can be a logical value TRUE only if the result of checking each of the specified conditions is a logical value TRUE. In other words, the function AND allows you to test one, two or more hypotheses on their truth, and returns the result FALSE if at least one of them is incorrect.

Sometimes you want to know if at least one assumption is true. In this case, it is convenient to use the OR function, which performs the check of one or several logical expressions and returns a logical TRUE, if the result of the calculations of at least one of them is a logical TRUE. For example, you want to know if e3 is an integer or a number that is less than 100? To test this condition, you can use the following formula:

=IF(OR(MOD(EXP(3),1)<>0,EXP(3)<100),»true»,»false»)

The “<>” means inequality, that is, more or less than some value. In this case, both expressions return the value TRUE, and the result of the execution of the IF function is the text string «true.» However, if an OR test was performed (MOD(EXP (3),1)<>0,EXP(3)<20, while EXP(3) <20 will return FALSE, the result of the calculation of the IF function will not change, since MOD(EXP(3),1) <> 0 returns TRUE.

Download examples using the functions OR AND IF in Excel

In practice, often used bundles IF + AND, IF + OR, or all three functions at once. Consider examples of similar use of these functions.

excel logo

Logical functions are some of the most popular and useful in Excel. They can test values in other cells and perform actions dependent upon the result of the test. This helps us to automate tasks in our spreadsheets.

How to Use the IF Function

The IF function is the main logical function in Excel and is, therefore, the one to understand first. It will appear numerous times throughout this article.

Let’s have a look at the structure of the IF function, and then see some examples of its use.

The IF function accepts 3 bits of information:

=IF(logical_test, [value_if_true], [value_if_false])
  • logical_test: This is the condition for the function to check.
  • value_if_true: The action to perform if the condition is met, or is true.
  • value_if_false: The action to perform if the condition is not met, or is false.

Comparison Operators to Use with Logical Functions

When performing the logical test with cell values, you need to be familiar with the comparison operators. You can see a breakdown of these in the table below.

Comparison operators for logical functions

Now let’s look at some examples of it in action.

IF Function Example 1: Text Values

In this example, we want to test if a cell is equal to a specific phrase. The IF function is not case-sensitive so does not take upper and lower case letters into account.

The following formula is used in column C to display “No” if column B contains the text “Completed” and “Yes” if it contains anything else.

=IF(B2="Completed","No","Yes")

IF function to test text values

Although the IF function is not case sensitive, the text must be an exact match.

IF Function Example 2: Numeric Values

The IF function is also great for comparing numeric values.

In the formula below we test if cell B2 contains a number greater than or equal to 75. If it does, then we display the word “Pass,” and if not the word “Fail.”

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

If condition with numeric values

The IF function is a lot more than just displaying different text on the result of a test. We can also use it to run different calculations.

In this example, we want to give a 10% discount if the customer spends a certain amount of money. We will use £3,000 as an example.

=IF(B2>=3000,B2*90%,B2)

Conditional formula by using the IF function

The B2*90% part of the formula is a way that you can subtract 10% from the value in cell B2. There are many ways of doing this.

What’s important is that you can use any formula in the value_if_true or value_if_false sections. And running different formulas dependent upon the values of other cells is a very powerful skill to have.

IF Function Example 3: Date Values

In this third example, we use the IF function to track a list of due dates. We want to display the word “Overdue” if the date in column B is in the past. But if the date is in the future, calculate the number of days until the due date.

The formula below is used in column C. We check if the due date in cell B2 is less than today’s date (The TODAY function returns today’s date from the computer’s clock).

=IF(B2<TODAY(),"Overdue",B2-TODAY())

Testing if dates are due

What are Nested IF Formulas?

You may have heard of the term nested IFs before. This means that we can write an IF function within another IF function. We may want to do this if we have more than two actions to perform.

One IF function is capable of performing two actions (the value_if_true and value_if_false ). But if we embed (or nest) another IF function in the value_if_false section, then we can perform another action.

Take this example where we want to display the word “Excellent” if the value in cell B2 is greater than or equal to 90, display “Good” if the value is greater than or equal to 75, and display “Poor” if anything else.

=IF(B2>=90,"Excellent",IF(B2>=75,"Good","Poor"))

We have now extended our formula to beyond what just one IF function can do. And you can nest more IF functions if necessary.

Notice the two closing brackets on the end of the formula—one for each IF function.

There are alternative formulas that can be cleaner than this nested IF approach. One very useful alternative is the SWITCH function in Excel.

The AND and OR functions are used when you want to perform more than one comparison in your formula. The IF function alone can only handle one condition, or comparison.

Take an example where we discount a value by 10% dependent upon the amount a customer spends and how many years they have been a customer.

On their own, the AND and OR functions will return the value of TRUE or FALSE.

The AND function returns TRUE only if every condition is met, and otherwise returns FALSE. The OR function returns TRUE if one or all of the conditions are met, and returns FALSE only if no conditions are met.

These functions can test up to 255 conditions, so are certainly not limited to just two conditions like is demonstrated here.

Below is the structure of the AND and OR functions. They are written the same. Just substitute the name AND for OR. It is just their logic which is different.

=AND(logical1, [logical2] ...)

Let’s see an example of both of them evaluating two conditions.

AND Function example

The AND function is used below to test if the customer spends at least £3,000 and has been a customer for at least three years.

=AND(B2>=3000,C2>=3)

AND function in Excel

You can see that it returns FALSE for Matt and Terry because although they both meet one of the criteria, they need to meet both with the AND function.

OR Function Example

The OR function is used below to test if the customer spends at least £3,000 or has been a customer for at least three years.

=OR(B2>=3000,C2>=3)

The OR logical function

In this example, the formula returns TRUE for Matt and Terry. Only Julie and Gillian fail both conditions and return the value of FALSE.

Using AND and OR with the IF Function

Because the AND and OR functions return the value of TRUE or FALSE when used alone, it’s rare to use them by themselves.

Instead, you’ll typically use them with the IF function, or within an Excel feature such as Conditional Formatting or Data Validation to perform some retrospective action if the formula evaluates to TRUE.

In the formula below, the AND function is nested inside the IF function’s logical test. If the AND function returns TRUE then 10% is discounted from the amount in column B; otherwise, no discount is given and the value in column B is repeated in column D.

=IF(AND(B2>=3000,C2>=3),B2*90%,B2)

Excel formula with IF and AND functions

The XOR Function

In addition to the OR function, there is also an exclusive OR function. This is called the XOR function. The XOR function was introduced with the Excel 2013 version.

This function can take some effort to understand, so a practical example is shown.

The structure of the XOR function is the same as the OR function.

=XOR(logical1, [logical2] ...)

When evaluating just two conditions the XOR function returns:

  • TRUE if either condition evaluates to TRUE.
  • FALSE if both conditions are TRUE, or neither condition is TRUE.

This differs from the OR function because that would return TRUE if both conditions were TRUE.

This function gets a little more confusing when more conditions are added. Then the XOR function returns:

  • TRUE if an odd number of conditions return TRUE.
  • FALSE if an even number of conditions result in TRUE, or if all conditions are FALSE.

Let’s look at a simple example of the XOR function.

In this example, sales are split over two halves of the year. If a salesperson sells £3,000 or more in both halves then they are assigned Gold standard. This is achieved with an AND function with IF like earlier in the article.

But if they sell £3,000 or more in either half then we want to assign them Silver status. If they don’t sell £3,000 or more in both then nothing.

The XOR function is perfect for this logic. The formula below is entered into column E and shows the XOR function with IF to display  “Yes” or “No” only if either condition is met.

=IF(XOR(B2>=3000,C2>=3000),"Yes","No")

The XOR Function in Excel

The NOT Function

The final logical function to discuss in this article is the NOT function, and we have left the simplest for last. Although sometimes it can be hard to see the ‘real world’ uses of the function at first.

The NOT function reverses the value of its argument. So if the logical value is TRUE, then it returns FALSE. And if the logical value is FALSE, it will return TRUE.

This will be easier to explain with some examples.

The structure of the NOT function is;

=NOT(logical)

NOT Function Example 1

In this example, imagine we have a head office in London and then many other regional sites. We want to display the word “Yes” if the site is anything except London, and “No” if it is London.

The NOT function has been nested in the logical test of the IF function below to reverse the TRUE result.

=IF(NOT(B2="London"),"Yes","No")

This can also be achieved by using the NOT logical operator of <>. Below is an example.

=IF(B2<>"London","Yes","No")

NOT Function Example 2

The NOT function is useful when working with information functions in Excel. These are a group of functions in Excel that check something, and return TRUE if the check is a success, and FALSE if it is not.

For example, the ISTEXT function will check if a cell contains text and return TRUE if it does and FALSE if it does not. The NOT function is helpful because it can reverse the result of these functions.

In the example below, we want to pay a salesperson 5% of the amount they upsell. But if they did not upsell anything, the word “None” is in the cell and this will produce an error in the formula.

The ISTEXT function is used to check for the presence of text. This returns TRUE if there is text, so the NOT function reverses this to FALSE. And the IF performs its calculation.

=IF(NOT(ISTEXT(B2)),B2*5%,0)

NOT function example 2

Mastering logical functions will give you a big advantage as an Excel user. To be able to test and compare values in cells and perform different actions based on those results is very useful.


This article has covered the best logical functions used today. Recent versions of Excel have seen the introduction of more functions added to this library, such as the XOR function mentioned in this article. Keeping up to date with these new additions will keep you ahead of the crowd.

READ NEXT

  • › How to Use the FILTER Function in Microsoft Excel
  • › How to Evaluate Formulas Step-by-Step in Microsoft Excel
  • › How to Count Characters in Microsoft Excel
  • › How to Use an Advanced Filter in Microsoft Excel
  • › How to Use the IF Function in Microsoft Excel
  • › How to Use the IS Functions in Microsoft Excel
  • › How to Find the Function You Need in Microsoft Excel
  • › How to Adjust and Change Discord Fonts

In this tutorial I will show you how to use the Excel Logical functions such as IF, AND and OR. They are super useful if you need to calculate some values based on some logical criteria.

For example you only want a field to show you a number when another field is bigger than a specific value. In the following I’ll teach you how to do this:

IF Function

If you need to check whether a condition is met in one of your workbooks then use Excel’s IF Function.

The IF function checks whether a condition is met and returns a specific value you select when it’s true, and another one when it’s false. Note that you can choose which values are returned by Excel.

Insert the following function in your Excel workbook:

=IF(A1>5,"Correct","Incorrect")

Excel will now check whether the value of cell A1 is greater than 5 and will return Correct if it’s true and Incorrect if it’s false in the cell where you inserted the IF Function.

Example of an Excel IF Function

Example of an Excel IF Function

Note that the IF Function returns Correct because the value in cell A1 is greater than 5.

How to use the AND Function

If you need to check whether multiple conditions are met in your Excel workbook then use the AND Function. The AND Function returns TRUE if all criteria are met and FALSE if any one of multiple criteria is not met.

Insert the following function in your Excel workbook:

=IF(AND(A1>5,B1>20), "Correct","Incorrect")

Excel will now check whether the value of cell A1 is greater than 5 the value of cell B1 is greater than 20. If both conditions are true, Excel will return Correct and if any of them is false Excel will return Incorrect in the cell where you inserted the IF Function.

Example of an Excel AND Function

Example of an Excel AND Function

Note that the AND Function returns FALSE since the value in cell B1 is not higher than 20.

How to use the OR function in Excel

If you need to check whether one of several conditions is met in your Excel workbook then use the OR Function. The OR Function returns TRUE if any of several conditions is met and FALSE if none of the conditions are met.

Insert the following formula in your Excel workbook:

=IF(OR(A1>5,B1>20),"Correct","Incorrect")

Excel will now check if the value of cell A1 is greater than 5, if the value of cell B1 is greater than 20, or if both conditions are met. If either one or both are true, then Excel will return Correct while it will return Incorrect in the cell where you inserted the IF Function in case none of the criteria are met.

Example of an Excel OR Function

Example of an Excel OR Function

The OR Function returns TRUE since the value in cell A1 is greater than 5.

To show how powerful this can be, know that you can use AND and OR functions to check up to 255 conditions simultaneously.

That’s it for logical functions in Excel. I hope that this tutorials was helpful in explaining the concepts of logical functions in Excel to you.

Can you tell me in the comments if and how you’re using one of the IF, AND, or OR functions already? I’d love to learn what you do.

The IF function helps to determine what will be displayed to those who view your worksheets in Excel. Because of its purpose, it’s one of the most important functions you will learn. IF functions can be used to add comments to your data. They can also be used to hide errors in calculations.

In this article, we will learn about:

  • The IF function

  • The IFNA and IFERROR functions

  • Nesting IF functions

  • The AND operator

  • The OR operator

  • The NOT operator

  • Displaying formulas from one cell in another

The syntax for the IF function is =IF. This lets Excel know that it is an IF function.

Then, we begin the formula that Excel will use to produce the results we want.

We start with an opening bracket:

Next, we add the evaluation criteria. For example, is six greater than three? The evaluation criteria asks a question. The question has two outcomes. If the answer (or outcome) is correct, such as «Yes, six is greater than three,» then the answer is true. If not it is false.

If it’s true, we put what happens when the answer is true.

If it’s false, we put what happens when it’s false.

In the worksheet below, we have a list of employees, followed by the rating they received as part of their annual review. 

Now, we want to add another column called Comments.   In this column, we want to add comments about the scores. This way, when a manager looks at the worksheet, he/she doesn’t need to worry themselves with the actual rating – and what that means. They can simply look in comments.

To add a comment based on the rating, we are going to use the IF function.

We have started the formula in the snapshot above.

We have said if the employee’s rating is less than fifty…

Now we enter what happens.

If it is correct that the employee’s rating is less than fifty, the comment should be «needs significant improvement.   However, if it’s false and if the rating is not less than fifty, the comment should be needs improvement.

Notice that we use quotation marks to enter the comments into the formula. 

Now, add an end bracket, then push Enter.

Since this contains a formula where all are cell references are relative, you can use the handle in the lower right corner of the cell, then drag it down to complete the comments for the other employees.

You can also use the IF function to hide Excel error messages.

Let’s show you what we mean by taking a look at the worksheet below.

In this worksheet, we have a formula that will divide cell C2 by cell D2.

If we push enter in cell A2, it will give us the answer.

However, let’s say the data in cell D2 is missing.

When we push Enter, we see an error message.

We can use the IF function to hide this error message.

To do this, we write the formula below:

Let’s translate what it says.   If D2 equals 0, enter two dashes into cell A2 where we have our formula. If it doesn’t equal zero, then go ahead and divide cell C2 by D2.

If we would put the number five back into cell D2 and leave the IF formula in place, we would see the answer to C2/D2.

Here’s our worksheet below. We have hidden the error message with two dashes.

NOTE: All of the IF functions appear under the Formulas tab and by clicking the Logical button. From there, you can access the Function Arguments dialogue box.

The IFNA and IFERROR Functions

The IFNA function tells Excel what to do if an #NA error is produced, whereas the isna tells Excel what to do if the returned value is #NA. 

The #NA error appears in a cell when a value is not available to a formula.

If in our worksheet below, we wanted to find the mode, we would enter this formula:

When we push Enter, the result is displayed.

However, if we went back and changed the second instance of the number four to a six, we would see an #NA error because the value needed is not available to determine the mode.

To avoid #NA values from appearing, we could use the new IFNA function.

It would be entered like this:

All of the IF functions appear under the Formulas tab and by clicking the Logical button. The easiest way to use the IFNA function is to click the Logical button, then select IFNA.

Below you can see the dialogue box for the IFNA function.

The IFERROR function can be used as a general «cover all» for any errors that might appear in your data. You can use it to specify what will be entered if any error occurs in the calculation of a formula.

It is written the same way as an IF function. However, instead of writing IF, you would write IFERROR. You can access the dialogue box for IFERROR by going to the Logical button under the Formulas tab.

Nesting IF Statements

Just as with VLOOKUPs and HLOOKUPs, you can nest an IF statement within an IF statement.

In our worksheet below, we have a list of friends, along with their ages.

We could create a simple IF formula to enter comments.

This says if the age is greater than 50, then the comment is getting older. If it’s less than 50, then they’re still young.

If we nest an IF statement within the current IF statement, we would keep the evaluation criteria, but we would replace one of the outcomes with our new IF statement. However, keep in mind, then when you nest an IF statement, you do not need another equal sign.

Take a look at our new formula below:

We have our original IF statement intact. We have highlighted the first part of it below.

If the age is greater than 50, followed by the two outcomes.

As you can see in our formula above, the TRUE outcome has another IF statement.

The nested IF statement tells Excel that if the age is greater than 70, enter the comment «old.» If it’s not, enter getting older. 

Our worksheet is shown below with the nested IF statements determining what comment is displayed.

Now, let’s break this down into easy to understand terms.

When you enter the formula above with a nested IF statement, Excel reads the first IF statement. It looks at your criteria, then the outcomes for the criteria.

If the outcome for the first IF statement is true, Excel is then going to perform another IF statement to determine what appears in the comments.   It will put «old» if the age is greater than 70. It will put getting older if it’s not greater than 70.   It’s very important to remember that these two outcomes both serve as your TRUE outcome for the first IF function. 

Now, if your original IF statement returns a FALSE outcome, then Excel will enter «still young.»

A nested IF statement gives you a way to enter more than one response for an outcome.

We used a nested if statement for the TRUE outcome. However, you can also use a nested IF statement for a FALSE outcome.

If the nested IF statements are still confusing to you, remember it this way: the nested IF statement provides two additional outcomes for either the TRUE or FALSE outcome of your original IF statement. 

Using the AND Operator in an IF Statement

You use the AND operator within an IF statement if you have more than one criteria that needs to be true. Using the AND operator can sometimes be easier to write than multiple nested IF statements.

Take a look at the worksheet below.

In it, we have a list of students and their grades for the four grading periods.

Each student must have earned greater than 80% in each quarter in order to receive an award. We will use the AND operator to set this as criteria.

Take a look at how at the formula bar to see how we wrote this.

 

Now, let’s examine it.

We start out by starting the IF statement with =IF, then the open bracket.  

Next, we write AND for the AND operator.   The criteria then is placed within brackets. Notice that we have four sets of criteria. The criteria is that each quarter’s grades must be greater than 80%. Also notice that all percentages have been converted to decimals when entered in as criteria.

After you’ve entered the criteria in brackets, you can enter your TRUE and FALSE values.   We want the cell to display «Yes» if the criteria is met.   We want it do display «No» if it is not met. We then type in an end bracket to close the IF statement.

Press Enter.

As you can see above, student Mary had one grade that was 80%. All of the grades had to be above 80% to meet our criteria, so a NO was returned.

You can now drag the handle in the cell down to complete the worksheet for all students.

Using the OR Operator in an IF Statement

The OR operator works in the same way as the AND, except it says if one of the criteria listed is true, then the outcome for TRUE is what is displayed.

Let’s look at our worksheet.

This time, we want to say if the grade for Q1, Q2, Q3, or Q4 is greater than 90%, then the student gets the award.

You enter it in the same way you did with the IF statement and the AND operator, expect you type OR instead of AND.

Press Enter.

You can then complete the worksheet.

Now let’s make it a bit more complicated.

Now we want to say that in order to get the award, the average of all four quarters must be greater than 90% OR at least one of the quarters must be greater than 95%.

In other words, the average of the quarters must be greater than 90%. Or Q1, Q2, Q3, or Q4 must be higher than 95%.

This is the perfect time for you to test your ability writing formulas by entering the formula into the cell.

Press Enter.

Using the NOT Operator

The NOT operator is used in conjunction with the AND or OR operator. 

The best way to explain how the NOT operator works is to show you the NOT operator in action.

Working with our students and grades again, we want to determine if the grades have improved each quarter.

To do that, we are going to use the IF statement with the AND operator since we are using multiple criteria. 

We will use the NOT operator to make sure Q1 is not higher than Q2. Q2 must be greater than Q1. 

In addition, Q3 must be greater than Q2, and Q4 must be greater than Q3. 

We’ve started the write it below:

Let’s finish.

Hit Enter.

We can see there is not steady improvement.

Remember: The NOT Operator is used within AND or IF options. You must use the NOT operator for each piece of criteria. You cannot type in the NOT operator once, then use it for all criteria.

Displaying Cell Formulas In Another Cell

Starting with Excel 2013, you can display the formula from one cell in another.   In our worksheets so far, we could view the formula in a cell by double clicking on the cell. However, once we pressed Enter or tabbed out of a cell, we couldn’t see the formula unless we looked in the Formula Bar.

To display a formula from one cell in another cell, go to the cell where you want to formula to appear.

You will use the FORMULATEXT function.

Type the equal sign, followed by formula text.

Enter an open bracket, then click the cell that contains the formula you want to display.

Add the closing bracket.

For our example, we are going to display the formula in cell G3 in sell H3.

Press Enter.

   

Понравилась статья? Поделить с друзьями:
  • If or and together in excel
  • If or and excel tutorial
  • If only we can find the word
  • If one value is true excel
  • If one cell changes vba excel