Sie sind auf Seite 1von 12

INDEX

 Excel IF Function
 Writing the function
 Nested IF Functions
 IF with AND
 IF with OR
 Questions
Excel IF Function

 The IF function is a logical function. It checks if a certain


condition is true or false and then acts accordingly.
 For example, if a student has scored more than 50 points in a
test, print “passed”, if not, print “Failed”.

Most common uses:

 Comparing values (is A1 greater than B1?)

 Using calculations based on the result of the comparing values (if


A1 is greater than B1, multiply A1 by 10)
Excel IF Function

Syntax

If function has the following syntax:

IF(logical_test, value_if_true, value_if_false)


Excel IF Function
To test whether a condition is true or not, you can use logical
operators. Excel supports the following logical operators:

< Less than


> Greater than
<= Less than or equal to
>= Greater than or equal to
= Equal to
<> Not equal to
Writing the function
we'll start building our formula. We'll need to have a formula on each row, so we'll start by typing the formula in cell xx.
As with any formula, you'll start with an equals sign (=). Then type the function name, followed by an open parenthesis.
So far, it should look like this:

=IF(

Now, we'll add our arguments. The arguments will tell the IF function what to look for and what to write in the cell
depending on the outcome.

The first argument sets up the condition we want to test. For this formula, we want to know if the value in cell xx is
greater than or equal to 50. We'll use some mathematical operators ( > for greater than and = for equals ) to write the
condition:

=IF(xx>=50

The next argument will tell the function what to write if the condition is true (that is, if the value is greater than or equal
to 50). This means the person will be passes, so we'll have it write Passed. Because this argument is text, we'll need to
put it in double quotes (" "). And, as with any function, we'll need to use a comma to separate each argument:

=IF(G2>=50, “Passed"

The final argument will tell the function what to write if the condition is false. This means the person will Failed., so go
ahead and close the parentheses:

=IF(xx>=50, “Passed", “Failed")

OK, you're done! When you press Enter, the words Passed/Failed should appear in the cell.
Writing the function
Let’s understand this using an example.

Suppose you have the results from a test where a score above 50 is
classified as “passed”, less than 50 classified as “failed”. You can do
this easily by using an Excel IF function:

=IF(xx<=50, “Passed”, “Failed”)

It’s sometimes easier to understand the IF function by putting it


into words. In the above example, we are essentially saying: if the
value in cell xx is less than 50, then type “Failed” into xx. If the
value is above 50, type “Passed” into xx.
Nested IF Functions
So far we’ve used the IF function to test only one condition. But
what if you need two or more conditions? Then we’ll use the
nested IF functions. This means we’ll use one (or more) IF functions
inside of another IF function.

Here’s the syntax for nested IF functions:

IF( condition1, value_if_true1, IF( condition2, value_if_true2,


value_if_false2 ))

In words, it works this way:


Basically, if the condition is NOT TRUE, we’ll add more IF functions.

Excel 2003 can nest up to 7 IF Functions, and Excel 2007, 2010 and
2013 allow 64 nested IF Functions.
Nested IF Functions
Using nested IF functions is to assign grades to students.
A -> 85 or above
B -> between 70 and 84
C -> between 60 and 69
D -> between 50 and 59
F -> below 50

Here’s the formula:


=IF(C3>=85,"A",IF(C3>=70,"B",IF(C3>=60,"C",IF(C3>=50,"D","F"))))
How to use nested IF statements in
Excel with AND

For the AND Function, formulas in multiple cells are tested and only
if all of these formulas are true will the function returns a TRUE
response. If not, the function returns FALSE as a value.

=IF(AND(first condition, second condition, …, etc.))


How to use nested IF statements
in Excel with OR

In the case of the OR function, if any one of the tested formulas is


true, then the OR function returns an answer of TRUE. Only if all
formulas are not true will OR give you a FALSE value in the cell where
it is located.

=IF(OR(first condition, second condition, …, etc.))


Questions

Das könnte Ihnen auch gefallen