Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 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: Using the IF Worksheet Function.

Using the IF Worksheet Function

by Allen Wyatt
(last updated November 23, 2018)

3

Excel provides a wide range of worksheet functions you can use. One of the most versatile worksheet functions is IF. This function allows you to test some condition, and then use a value if the condition is true or a different value if the condition is false. For instance, consider the following example:

=IF(A2<C2,"Too low","")

Notice that IF requires three arguments, each separated by commas. The first argument (in this example, A2<C2) is the conditional test. If the test proves true, then the second argument (in this case, the test string "Too low") is used. If the test proves false, then the third argument (in this case, an empty string) is used. In other words, if the value in cell A2 is lower than the value in cell C2, then this formula returns the string "Too low." Otherwise, it returns an empty string.

You are not limited, of course, to returning strings in an IF function. You can return any value you want, including the values stored in other cells. For example:

=IF(A2<C2,B6-B7,43)

In this case, if A2 is less than C2, then the value derived by subtracting B7 from B6 is returned. If A2 is not less than C2, then the value 43 is returned.

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

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

Inserting an Em Dash

Em dashes are often used to combine independent clauses or to signal digression within a sentence. Here's how to add one ...

Discover More

Determining if a Text Selection Exists

Macros are often designed to be run on just a selected portion of a document. It is a good idea to make sure that the ...

Discover More

Understanding Paragraph Alignment

One of the most basic ways to align paragraphs is to set the alignment used for the text in the paragraph. Word provides ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Using the XIRR Function

One of the financial worksheet functions provided in Excel is the XIRR function. This is used to figure out an internal ...

Discover More

Converting to Hexadecimal

Excel allows you to easily convert values from decimal to other numbering systems, such as hexadecimal. This tip explains ...

Discover More

The EDATE Function

Want to figure a date a certain number of months in the future or past? The EDATE function may be just what you need for ...

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}] 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 four minus 0?

2018-11-25 03:59:58

Chris van Zyl

Thanks for the hints Alan von Elstein; I was not aware of the choose function.


2018-11-24 05:14:11

Alan von Elstein

Hi Chris van Zyl,
You might be able to do something similar with a combination of other things…
One idea, Put this in top left of a spare spreadsheet, ( so red is in A1, orange is in B1 and A2, green is in A3 )
red orange
orange
green
Now put this formula in any cell .._
=CHOOSE(MATCH(B1,A1:A3,0),"Is red","Is Orange","Is Green")
_.. it is sort of doing a select case on B1, where the options are red, orange and green.
I expect using things like VLOOKUP, INDEX and MATCH you could come up with something similar, but I chose choose as I have not seen that used much, so thought it might be of interest to anyone who has not come across it before. ( A chap called snb made me aware of it )

You could further do that with an Array so that you need no use of the spreadsheet range
=CHOOSE(MATCH(B1,{"red";"orange";"green"},0),"Is red","Is Orange","Is Green")

_._____________________
( Excel Choose Function :-
https://support.office.com/en-us/article/choose-function-fc5c184f-cb62-4ec7-a46e-38653b98f5bc )

Alan von Elstein
(see Figure 1 below)

Figure 1. 


2018-11-23 03:56:31

Chris van Zyl

Thanks for this Allen. It would be good if there were also an equivalent to the vba "Select case" function too. Concatenated ifs can get rather unwieldy...


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.