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

Determining if Overtype Mode is Active

Your macro may need to determine if the user has overtype mode turned on. You can find out the overtype status easily by ...

Discover More

Quickly Changing Document Windows

When working with multiple documents at the same time, you often have a need to move from one document to another. Here's ...

Discover More

Static Sizes for Comment Boxes

Adding comments to your worksheet can be helpful in documenting what the worksheet contains. If you want to make sure ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Finding the Nth Root of a Number

Finding a square root is easy because Excel provides a worksheet function for that purpose. Finding a different root may ...

Discover More

Using the EOMONTH Function

If you need to determine the date of the last day in a month, it's hard to beat the flexibility of the EOMONTH function. ...

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
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 five more than 5?

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.