How to Do Nested IF Statements in Excel

Updated on September 21, 2016

Learning how to use nested IF statements in Excel will make your life easier and you will become much more efficient in Excel. Nested IF statements are a powerful way to perform complex calculations in a single cell. As an accountant, I use nested IF statements every day at work and I do not know what I would do without them.

What is a Nested IF Statement?

You may be thinking what exactly is a nested IF statement? A nested IF statement contains at least one IF statement inside of another as part of the argument. I think that the most nested IF statements that I have used in a formula are eleven when I was trying to control a year-to-date sales formula. You can also use other nested functions inside of an IF statement such as OR, AND, and NOT.

Nested IF Statements in Excel

Source

Think of nested IF statements this way: If a condition is true, then enter this value, if it is not true, check to see if it meets the next condition. Is that condition true, if so, enter this value, otherwise if it is false, enter this value. Nested IF Statements may look complicated and seem hard to follow, but once you understand what Excel is looking for, they are actually quite simple to create. The picture above shows in detail what Excel requires for a formula with one nested IF statement. Let us take a look at the individual requirements in more detail.

Logical Test

The logical test is the value or expression that you want to test to see if it is true or false. You can use any calculation operator (=, >, <, <>, etc.) that you want. A great example would be B36=10. Excel will then look in cell B36 to see if it does equal 10 or not. This is a required field.

Value if True

The value if true parameter is simply the value that the formula will display if the Logical Test comes back as true. If this argument is left blank, then Excel will return a zero if the formula is true. The Value if True can be a number, text, formula, cell reference, or it can return a blank cell by using "".

Nested IF Statement

A nested IF statement will begin again with the Logical Test followed by the Value if True and repeated as many times as needed up to a total of 64 if you are using Excel 2007 or newer. Older versions of Excel limited you to seven times.

Value if False

The Value if False parameter is the value or expression that the formula will display if the Logical Test comes back as false. If this argument is left blank, then Excel will return the logical value of false. The Value if False can be a number, text, formula, cell reference, or it can return a blank cell by using "".

Example of Using Nested IF Statements in Excel

Now that we know what Excel is looking for, let us walk through a step by step example. I set up a spreadsheet that has three high-level income statements on it, one for actual results, one for budgeted results, and the third one for an actual versus budget income statement, which will be controlled by a drop down box that selects the current month in cell B3. Below is a picture of what the spreadsheet looks like:

Source

Normally, if I was doing this for work, each income statement would be on its own tab. I placed everything on one tab to make the explanation of this example clearer.

Current Month Actual Income Statement

Pulling only the current month information is much quicker and easier than the year to date data. Click in cell B23 and enter the following formula:

=IF($B$3="January",$B8,IF($B$3="February",$C8,IF($B$3="March",$D8,IF($B$3="April",$E8,IF($B$3="May",$F8,IF($B$3="June",$G8,IF($B$3="July",$H8,IF($B$3="August",$I8,IF($B$3="September",$J8,IF($B$3="October",$K8,IF($B$3="November",$L8,IF($B$3="December","Error!!!"))))))))))))

I know that is a lot to digest all at once. Let us break it down into understandable chucks.

=IF($B$3="January",

The first part of the formula is the Logical Test and it looks up the contents of cell B3 to see if they equal January. There are two other things that I want to mention here. First, the $ on each side of the cell reference serve to anchor it so that no matter where this formula is copied and pasted, it will always point to cell B3. The second thing is that whenever you are looking for a text value in Excel, you have to enclose it in quotation marks.

=IF($B$3="January",$B8,

The next part of the formula is the Value if True and says that if cell B3 equals January, then return cell B8, which is the actual sales amount for January. Notice the $ to the left of B8, it is there to hold the column reference only. It will allow the row reference to change.

=IF($B$3="January",$B8,IF($B$3="February",$C8,IF($B$3="March",$D8,IF($B$3="April",$E8,IF($B$3="May",$F8,IF($B$3="June",$G8,IF($B$3="July",$H8,IF($B$3="August",$I8,IF($B$3="September",$J8,IF($B$3="October",$K8,IF($B$3="November",$L8,IF($B$3="December",

The rest of the formula repeats itself. Notice how the Logical Test changes each time to test for a different month. Also, the Value if True changes a column each month to pick up the correct income statement amount.

=IF($B$3="January",$B8,IF($B$3="February",$C8,IF($B$3="March",$D8,IF($B$3="April",$E8,IF($B$3="May",$F8,IF($B$3="June",$G8,IF($B$3="July",$H8,IF($B$3="August",$I8,IF($B$3="September",$J8,IF($B$3="October",$K8,IF($B$3="November",$L8,IF($B$3="December","Error!!!"))))))))))))

Finally, we get to the Value if False argument. I prefer to add an error message just in case the value in cell B3 becomes something that it should not be. You could end with December being the Value if False if you wanted too. Also, it is important that you add the exact amount of closing parenthesizes as you have opening ones. Hit the enter key and you should now see this:

Source

Copy the formula in B23 and paste it into cells B24 and B25. Notice that the cell B26 is now equal to cell D11.

Source

Have you ever used a nested IF statement before?

See results

Current Month Budgeted Income Statement

Next we need to bring in the budgeted income statement. There are two ways to do this. Either we could enter another lengthy formula from scratch or we could use a little trick that I learned. Normally, I would have each of these income statements on separate tabs, perfectly lined up with each other. Then all we would have to do is copy the formula over since we anchored the column headings and it would correctly pull the right month. However, since everything is on one tab, the budget data does not line up with the same row references. Thankfully, I have another trick up my sleeve. Copy cell B23 and paste it into C23. All of the column references should still be the same (start with B in the first Logical Test and end with M in the last one). See the picture below:

Source

Video Example of Using Nested IF Statements to Assign Letter Grades

Highlight cells C23 through D23. Hit Cntrl + H, which will bring up a Find and Replace dialogue box. In the "Find what:" box, enter "8". In the "Replace with:" box, enter 15. We want to Excel to find all of the references to 8 in the formula and replace them with 15. Basically what this is doing is changing the row that the Value if True argument is going to return if the Logical Test returns as true. It is important that more than one cell is highlighted, otherwise, Excel will replace all references to 8 on the spreadsheet. Copy the cell C23 down and paste it into cells C24 and C25. Your actual versus budget income statement should now look like this:

Source

The actual versus budget income statement can also be setup to show the year to date balances of each. The only difference would be that each month in the Value if True argument, you add up each month to that point. The formula would look like this:

=IF($B$3="January",$B8,IF($B$3="February",$B8+$C8,IF($B$3="March",$B8+$C8+$D8,IF($B$3="April",$B8+$C8+$D8+$E8,IF($B$3="May",$B8+$C8+$D8+$E8+$F8,IF($B$3="June",$B8+$C8+$D8+$E8+$F8+$G8,IF($B$3="July",$B8+$C8+$D8+$E8+$F8+$G8+$H8,IF($B$3="August",$B8+$C8+$D8+$E8+$F8+$G8+$H8+$I8,IF($B$3="September",$B8+$C8+$D8+$E8+$F8+$G8+$H8+$I8+$J8,IF($B$3="October",$B8+$C8+$D8+$E8+$F8+$G8+$H8+$I8+$J8+$K8,IF($B$3="November",$B8+$C8+$D8+$E8+$F8+$G8+$H8+$I8+$J8+$K8+$L8,IF($B$3="December",$B8+$C8+$D8+$E8+$F8+$G8+$H8+$I8+$J8+$K8+$L8+$M8,"Error!!!"))))))))))))

Source

For anyone who works with Excel on a regular basis, I would highly recommend that they learn how to use nested IF statements. They are an invaluable tool for data manipulation and for compiling reports. I can say from personal experience that they have made me much more efficient in Excel.

Questions & Answers

    © 2014 Eric Cramer

    Comments

      0 of 8192 characters used
      Post Comment

      • Larry Rankin profile image

        Larry Rankin 

        3 years ago from Oklahoma

        When it comes to Excel, I can use all the help I can get.

        Great Hub!

      • ubrish profile image

        ubrish ali 

        3 years ago from Pakistan(Asia)

        So much information about excel.thanks for sharing

      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)