Using the IF and IFERROR Functions in Excel 2007 and 2010

Updated on December 16, 2016

Introduction

Welcome to my latest article on Excel. Today I am going to look at the IF and IFERROR functions. The IF statement compares the cell you provide with what you tell Excel to look for and returns one result if it is true and another if it is false. The IFERROR function permits us to suppress expected errors in our spreadsheets.

The IF statement is made up of three elements:

  • What it is Excel is looking for.
  • What you want it to do if it is true.
  • What to do if it is false.

If you don’t tell Excel what to do if it is false, Excel will just return FALSE as a result.

There are a number of situations where you may want to use an IF statement:

  • When you are comparing the contents of your cell with something else e.g. “Does the cell I am interested in contain the word Blue?”
  • Calculating something based on the cells contents e.g. “Does Billy Smith’s exam results earn him a B grade?”
  • Converting the cells contents to something else e.g. “If B2=1 then I want C2 to display “Aries”.

We will work through examples of each as well as how to use IF with the AND, OR, and NOT functions.

  • If we use IF and AND together, Excel will do one thing if all the conditions are met and the other if they are not all met
  • When using IF and OR, Excel will do one thing if one of the conditions is met and another if none are met
  • Using IF and NOT together, Excel will do one thing if the condition is not met and another if it is.

In addition, we will look at the IFERROR function which allows us to suppress expected errors.

Example of Using an IF Statement

To begin, we will look at a simple example of the IF statement. Here we are comparing the contents of the cell with the word blue.

=IF(A2="Blue", "Cell is Blue", "Cell is not Blue")

Example of a simple IF statement in Excel 2007 and Excel 2010.
Example of a simple IF statement in Excel 2007 and Excel 2010. | Source

Using Multiple IF Statements

Suppose rather than asking Excel to compare the cell with one thing, we want Excel to compare it against a number of things. We can use multiple IF statements in formula. You can see an example of such a formula below:

=IF(L5=1,"15",IF(L5=2,"20",IF(L5=3,"25",IF(L5=4,"30"))))

Pay particular attention to the brackets in the above formula. Notice that all the open brackets are on the left and that all the closed brackets are on the right (the IF statements are separated by commas rather than closed brackets.) This nests the IF statements within each other.

Using IF With AND Function

Using the logical function AND with IF allows you to test the contents of your cell using more than one condition. We can use AND to determine if Billy has earned a B grade in his recent test. To gain a B he needed to score between 75 and 90.

=IF(AND(B13>B6,B13<B5),"B")

Using IF and AND in a formula in Excel 2007 and Excel 2010.
Using IF and AND in a formula in Excel 2007 and Excel 2010. | Source
  • In the above formula, we look at the contents of cell B13
  • Using the AND function we check if it is greater than B6, which is the bottom boundary for the B grade, and less than B5, which is the top boundary for the B grade.
  • And if it is between those two numbers, we assign that mark a B grade.

Using IF With OR Function

Similar to AND, you use can use OR to test your cell against more than one condition. With OR, only one of the conditions has to be true for the IF statement to be true. For example, I would like to know if the content of cell A15 is cow or pig. If it is either of those, B15 will display mammal. If not, it will be blank.

=IF(OR(A15="Cow", A15="Pig"),"Mammal", "")

Excel looks at cell A15 and finds cow, it then looks at what it is supposed to be looking for which is cow or pig. As the condition is met, it will return “Mammal.” If it found chicken in cell A15, it would then return as chicken having not met the conditions of the OR function.

Using IF With NOT Function

The final logical function we will look at is NOT. It looks at a single value and determines whether or not it is the same as the cell it is comparing it with. In my example, I have a cell that contains the word Green. Excel looks at that cell and compares it with the word Blue. If it is not blue it returns green and if it is blue it returns blue.

Using IF with NOT in a formula in Excel 2007 and Excel 2010.
Using IF with NOT in a formula in Excel 2007 and Excel 2010. | Source

Converting the Contents of a Cell Using IF Statements

The third use of the IF statement in Excel is converting the contents of a cell into something else that we can use in a different way to its original contents. Often the result of a formula or the users selection from a drop down box is not in the format you need. You can use IF statements to convert it.

For an example, I have a drop down box that invites the user to select monthly or quarterly payments.

  • The drop down box places a 1 in cell L2 if the user selects monthly and 2 in L2 if the user selects quarterly.
  • Excel needs the number to calculate the number of annual repayments for the users mortgage and will be 4 if quarterly and 12 if monthly.

To achieve this, I use IF to convert 1 to 12 and 2 to 4 with the following formula:

=IF(L2=1,"12",IF(L2=2,"4"))

Using IF to convert the contents of a cell in Excel 2007 and Excel 2010.
Using IF to convert the contents of a cell in Excel 2007 and Excel 2010. | Source

Excel now uses the result which is stored in M2 to correctly calculate the formulas for the interest and principal paid each period.

Using the IFERROR Function

The last function we will look at today is the IFERROR function. This is used if you want to change the way Excel behaves if it produces an error. Often, depending on what a user does, Excel may alert you to an error which is expected.

Suppose someone uses my mortgage calculator to look at a mortgage over 35 years. They then change their mind and choose a 20 year mortgage. All the cells between 21 and 35 years will now display an error (a #NUM error.) To suppress that error we nest the original formula in IFERROR.

The original formula was:

=PPMT($R$2/$M$2,A35,$M$2*$M$5,-$F$16)

We add IFERROR like so:

=IFERROR(PPMT($R$2/$M$2,A35,$M$2*$M$5,-$F$16), " ")

What will now happen is that if there is an error in this cell it will display a single space rather than an error.

You should ensure that your formula works perfectly before nesting using IFERROR. Otherwise, you will never know if it produces an error due to a typo or other mistake.

Conclusion

We looked at the IF and IFERROR functions and used it together with the logical functions AND, OR, and NOT. IF can be used:

  • To compare a cell’s contents.
  • To convert a cell to something else.
  • And to perform a calculation on a cell based on what is in it.

Using the IF function we ask Excel to compare a cell with something we are interested in and do one thing if it is true and another if it is false. So if we have, for example, a cell containing the word parrot and we want Excel to look at that cell and return bird if the cell contains the word parrot and return not bird if it doesn’t then we can use IF to do this.

We also covered using multiple IF statements in one formula paying special attention to the brackets.

In combination with the other logical functions, we saw that:

  • If we use IF and AND together, Excel will do one thing if all the conditions are met and the other if they are not all met.
  • When using IF and OR. Excel will do one thing if one of the conditions is met and another if none are met.
  • Using IF and NOT together, Excel will do one thing if the condition is not met and another if it is.

The last function we examined was the IFERROR function. This allows you to suppress an expected error or change the text that Excel displays when an error occurs.

Many thanks for reading and I hope that you are now happily using the very versatile IF functions in your spreadsheets. Please feel free to leave any comments you may have below.

Questions & Answers

    Comments

      0 of 8192 characters used
      Post Comment

      No comments yet.

      working

      This website uses cookies

      As a user in the EEA, your approval is needed on a few things. To provide a better website experience, turbofuture.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

      For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://turbofuture.com/privacy-policy#gdpr

      Show Details
      Necessary
      HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
      LoginThis is necessary to sign in to the HubPages Service.
      Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
      AkismetThis is used to detect comment spam. (Privacy Policy)
      HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
      HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
      Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
      CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
      Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
      Features
      Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
      Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
      Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
      Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
      Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
      VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
      PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
      Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
      MavenThis supports the Maven widget and search functionality. (Privacy Policy)
      Marketing
      Google AdSenseThis is an ad network. (Privacy Policy)
      Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
      Index ExchangeThis is an ad network. (Privacy Policy)
      SovrnThis is an ad network. (Privacy Policy)
      Facebook AdsThis is an ad network. (Privacy Policy)
      Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
      AppNexusThis is an ad network. (Privacy Policy)
      OpenxThis is an ad network. (Privacy Policy)
      Rubicon ProjectThis is an ad network. (Privacy Policy)
      TripleLiftThis is an ad network. (Privacy Policy)
      Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
      Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
      Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
      Statistics
      Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
      ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
      Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)