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.
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!
Finding a square root is easy because Excel provides a worksheet function for that purpose. Finding a different root may ...
Discover MoreIf 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 MoreLooking for a great reference that you can use to help figure out the various worksheet functions available in Excel? ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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
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...
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2021 Sharon Parq Associates, Inc.
Comments