Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Nesting IF Worksheet Functions.

Nesting IF Worksheet Functions

Written by Allen Wyatt (last updated November 12, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


15

If you have done any programming, you know that you can create conditional statements known as If...Then statements. Basically, these statements give you a way to say "If this is true, then do that." Excel provides an IF worksheet function to accomplish essentially the same thing in a formula.

You already know how to use the IF function because it was covered in other ExcelTips. What you may not know is that you can nest IF functions. For instance, consider the situation where you want to return a value if two other conditions are true. If cell B5 contains a temperature setting and cell B6 contains a pressure setting, you may want cell B7 to contain the words "TOO HIGH" if B5 is greater than 100 and cell B6 is greater than 50. To do something like this, you could use the following formula:

=IF(B5>100,IF(B6>50,"TOO HIGH",""),"")

Notice that there are two IF functions here. The first one checks to see if the value of B5 is greater than 100. If it is, then the next IF function is invoked. This one checks to see if B6 is greater than 50. If it is, then the words "TOO HIGH" are displayed in the cell. If either of the conditional statements fail, then nothing is displayed in the cell.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12611) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Nesting IF Worksheet Functions.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Setting Spell-Checking Options

Like many things in Word, you can configure the way the spelling checker does its job. If you want to exercise more ...

Discover More

Replacing Graphics with Graphics

You can use the Find and Replace feature of Word to replace inline graphics with other graphics. This tip explains how ...

Discover More

Checkboxes in a Merged Document

When creating a mail-merge document, you may want to include some special characters, such as check-marked boxes, in the ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Understanding the VLOOKUP Function

Functions are at the heart of Excel's power in working with data. One of the most misunderstood functions provided by ...

Discover More

Outstanding Macro Function Reference

Looking for a great reference that you can use to help figure out the various worksheet functions available in Excel? ...

Discover More

Returning the Left-most Characters

When working with text in a formula, you may need to extract the left-most characters from a string of text or from a ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 2?

2021-11-22 10:12:44

J. Woolley

When you have a complex nested formula, the formula parser at http://www.formulaboost.com can be useful. Here is the result for this Tip's formula: (see Figure 1 below)
My Excel Toolbox includes the FormulaParser macro, which makes it easy to use that web site.
See https://sites.google.com/view/MyExcelToolbox/

Figure 1. 


2021-11-19 16:18:26

Tomek

@Yvan Loranger, Sorry, re-posted because a typo prevented proper formatting. Hope it works this time.

Because HTML treats consecutive spaces as a single white space,, and ignores leading and trailing spaces in any line, you cannot use spaces to indent text in comments. You have to resort to putting non-breakable spaces in your comment. You can do this using HTML code for nonbreakable space, which is  
 

See the following lines:
    Indented
        indented more.

For more on this, check the comments under the following tips:

https://excelribbon.tips.net/T011193_Using_Excel_for_Timing.html
https://excelribbon.tips.net/T010127_Negating_a_Cell_Using_a_Macro.html
https://excelribbon.tips.net/T011598_Limiting_Who_Can_Delete_Data.html
  Cheers!
 Tomek


2021-11-19 16:02:54

Yvan Loranger

2nd attempt, using Michael's suggestion of using underscores instead of spaces to indent:

Example 1 – from Excel Tips: Example 2 – an example of nesting IFs:
“Nesting IF Worksheet Functions” (I like to indent, I find it easier
to understand:)
IF (A1="US",____________________ IF (A1="US",
__ IF(A2>50,_______________________IF (A2>50,
_____B4=2,__________________________ B4=2,
_____B4=1___________________________B4=1
____ ),______________________________ ),
__ B4=1___________________________IF (A2>40,
__)__________________________________B4=1.5,
____________________________________ B4=1
____________________________________)
Example 1 rewritten:______________ )
IF ( AND(A1="US",
________A2>50
_______ ),
___ B4=2,
___ B4=1
__)


2021-11-18 16:10:47

Yvan Loranger

Drats, the indentation did not work (:


2021-11-18 16:05:42

Yvan Loranger

Example 1 – from Excel Tips: Example 2 – an example of nesting IFs:
“Nesting IF Worksheet Functions” (I like to indent, I find it easier
to understand:)
IF (A1="US", IF (A1="US",
IF(A2>50, IF (A2>50,
B4=2, B4=2,
B4=1 B4=1
), ),
B4=1 IF (A2>40,
) B4=1.5,
B4=1
)
Example 1 rewritten: )
IF ( AND(A1="US",
A2>50
),
B4=2,
B4=1
)


2021-10-18 10:10:05

J. Woolley

@Emma
This formula for 7:30 am tomorrow might help:
=INT(NOW())+1+TIMEVALUE("7:30 am")
Substitute your parameter for NOW().


2021-10-17 07:40:31

Emma

Hi,

Is there a way to use an IF formula to determine if a DD/MM/YYYY HH:MM minus another in the same format is a weekday and with working time range and if not change to the next day at the start time of the working day?

I have got the subtracting and a column to tell me if working or non-working but do not know how to set something to change it to the next 07:30 if out of the parameters?

Any help appreciated.

Thanks, Emma.


2018-05-04 03:41:13

Jens H. Bjørneboe

Michael Schenck: Just found out you don't need the spaces.

Using Win10 and Excel 2016


2018-05-01 03:03:50

Michael (Micky) Avidan

@Rkeev,
VLOOKUP. HLOOKUP, LOOKUP are al members of the same family.
I wouldn't dare using CHOOSE because the criteria is not always an Integer (CHOOSE needs an Integer as an index_num).
In addition the you cannot select a range for the results - such as: =CHOOSE(E7,F6:F10)
You need to put every result cell separately delimited by a comma.
----------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” Excel MVP – Excel (2009-2018)
ISRAEL


2018-04-30 10:06:17

Rkeev

Alternatively, Choose or Lookup (with a result vector) can also be used for this if you don't want the DEATH by IF statements.


2018-04-30 05:04:50

Michael (Micky) Avidan

@James McMichael,
This tip relates to "Excel 2007" and above.
Excel 97/2000/2003 had a limit of 7 nestings vut there were ways to get around that - for example: using VLOOKUP with a small helper table etc..
Excel 2007-2016 has a limit of 64(!)
----------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” Excel MVP – Excel (2009-2018)
ISRAEL


2018-04-29 08:53:33

James McMichael

Just don't try to nest them more than 7 deep, once this is done it will always evaluate to the false response.


2018-04-28 07:31:10

Michael Schenck

With apologies, the prior comment failed because the indents were stripped. Trying to paste the example here using underscores instead of spaces to show the indents, though that would not work in an actual Excel formula:

=IF(B5>100,
___IF(B6>50,
_____"TOO HIGH",
_____IF(B6>45,
_______"MARGINAL",
_______"")),
___IF(B5>90,
_____IF(B6>50,
_______"MARGINAL",
_______""),
_____""))


2018-04-28 07:24:24

Michael Schenck

It's an old programming trick, but when nesting IF statements, you can use carriage returns (Alt-Enter) and spaces to add structure to the nesting for readability. This allows you to change the nested IF statement above from =IF(B5>100,IF(B6>50,"TOO HIGH",""),"") to:

=IF(B5>100,
IF(B6>50,
"TOO HIGH",
""),
"")

The True and False results are more easily identified.

This is particularly valuable as IF statements become more complex since it makes them easier to debug (obviously the example below could be cleaned up using AND and OR statements):

=IF(B5>100,
IF(B6>50,
"TOO HIGH",
IF(B6>45,
"MARGINAL",
"")),
IF(B5>90,
IF(B6>50,
"MARGINAL",
""),
""))

NOTE: If cell contents are centered or right-justified it throws off thus formula structure. In that case, temporarily left-justify the cell when debugging.


2018-04-28 07:01:40

Ira Bernstein

Hi Allen
I'm a long time follower of Excel Tips. Shouldn't today's discussion of nesting IF statements have included the IFS function?


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.