Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. 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, and 2013. 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

Automatically Updating Fields and Links

You can update fields and links automatically when you print your document, but what if you want them updated when you ...

Discover More

Rotating a Drawing Object

You can add all sorts of drawing objects to a document. Once placed, you can then rotate them to your heart's content. ...

Discover More

Unable to Set Margins in a Document

If you find that you cannot set the margins in a document, chances are good that it is due to document corruption. Here's ...

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)

Getting the Name of the Parent Workbook

If you need to insert into a cell the name of the workbook in which a worksheet is contained, you can use the CELL ...

Discover More

Random Numbers in a Range

Excel provides several different functions that you can use to generate random numbers. One of the most useful is the ...

Discover More

Using the COLUMN Function

Need to know the column number for use in a formula? The worksheet function you want is the COLUMN function, described in ...

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 0 + 1?

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.