Functions are predefined formulas that perform calculations by using specific values, called arguments, in a particular order, or structure. Functions can be used to perform simple or complex calculations. You can find all of Excel's functions on the Formulas tab on the Ribbon:
IF FUNCTION IN EXCEL.
The IF function is one of the most popular and useful functions in Excel. You use an IF statement to ask Excel to test a condition and to return one value if the condition is met, and another value if the condition is not met.
The IF function is one of Excel's logical functions that evaluates a certain condition and returns the value you specify if the condition is TRUE, and another value if the condition is FALSE.
The syntax for Excel IF is as follows:
IF(logical_test, [value_if_true], [value_if_false])
As you see, the IF function has 3 arguments, but only the first one is obligatory, the other two are optional.
- logical_test - a value or logical expression that can be either TRUE or FALSE. Required.In this argument, you can specify a text value, date, number, or any comparison operator.For example, your logical test can be expressed as or B1="sold", B1<12/1/2014, B1=10 or B1>10.
- value_if_true - the value to return when the logical test evaluates to TRUE, i.e. if the condition is met. Optional.For example, the following formula will return the text "Good" if a value in cell B1 is greater than 10:
=IF(B1>10, "Good")
- value_if_false - the value to be returned if the logical test evaluates to FALSE, i.e. if the condition is not met.
Using the IF function in Excel - formula examples
Now that you are familiar with the Excel IF function's syntax, let's look at some formula examples and learn how to use IF as a worksheet function in Excel.
Excel IF statement for numbers: greater than, less than, equal to
The use of the IF function with numeric values is based on using different comparison operators to express your conditions. You will find the full list of logical operators illustrated with formula examples in the table below.
Condition | Operator | Formula Example | Description |
Greater than | > | =IF(A2>5, "OK",) | If the number in cell A2 is greater than 5, the formula returns "OK"; otherwise 0 is returned. |
Less than | < | =IF(A2<5, "OK", "") | If the number in cell A2 is less than 5, the formula returns "OK"; an empty string otherwise. |
Equal to | = | =IF(A2=5, "OK", "Wrong number") | If the number in cell A2 is equal to 5, the formula returns "OK"; otherwise the function displays "Wrong number". |
Not equal to | <> | =IF(A2<>5, "Wrong number", "OK") | If the number in cell A2 is not equal to 5, the formula returns "Wrong number "; otherwise - "OK". |
Greater than or equal to | >= | =IF(A2>=5, "OK", "Poor") | If the number in cell A2 is greater than or equal to 5, the formula returns "OK"; otherwise - "Poor". |
Less than or equal to | <= | =IF(A2<=5, "OK", "") | If the number in cell A2 is less than or equal to 5, the formula returns "OK"; an empty string otherwise. |
Excel IF function examples for text values
Generally, you write an Excel if statement with text using either "equal to" or "not equal to" operator, as demonstrated in a couple of IF examples that follow.
Example 1. Case-insensitive IF formula for text values
Like the overwhelming majority of Excel functions, IF is case-insensitive by default. What it means for you is that logical tests for text values do not recognize case in usual IF formulas.
For example, the following IF formula returns either "Yes" or "No" based on the "Delivery Status" (column C):
=IF(C2="delivered", "No", "Yes")
Translated into the plain English, the formula tells Excel to return "No" if a cell in column C contains the word "Delivered", otherwise return "Yes". At that, it does not really matter how you type the word "Delivered" in the logical_test argument - "delivered", "Delivered", or "DELIVERED". Nor does it matter whether the word "Delivered" is in lowercase or uppercase in the source table, as illustrated in the screenshot below.
No comments:
Post a Comment