Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CONTENTS IF statements
ConditionaI statements invoIving IogicaI tests with the IF function
Logical Tests in Excel are carried out by what is known as an Fstatement.
This is an Excel function that allows the contents of the cell in which it is housed to adopt
either of two distinct sets of values depending upon the result of the logical test.
The general construction of an if statement can be thought of as follows.
=IF(LogicaI test,ResuIt if test true,ResuIt if test faIse)
To make this general idea more specific, think of a number - any number. Now suppose that we want to
multiply this number by two if it is less than 100 but divide it by two if it is greater than or equal to 100.
We can build up the if statement that will do this as follows.
logical test is the number less than 100?
if it is then multiply the number by 2
otherwise divide the number by two
To continue enter any number of your choosing to the yellow cell below (C20).
We start with =IF(C20<100, this is the logical test.
Then we have C20*2, This the result if the test is true.
Finally we have C20/2 This is the result if the test is false
Putting the three parts together gives =IF(C20<100,C20*2,C20/2) Enter this now to the blue cell below (C21).
Now check that correct answers are returned for C20 values that
are respectively less than 100, or 100 or more.
The logical test above returned a numerical value in each of the two sets of circumstances.
However sometimes we may want a string of text to be returned. To do this we simply enclose each
of the desired text values in double quotes. For example suppose that in order to pass an examination
a minimum mark of 50 is required. Enter any mark between 0 and 100 to the yellow cell below (C28).
Now enter the following if statement to the blue cell below (C29) =IF(C28>=50,"PASS","FAIL")
Once again check your answer for marks that pass or fail.
PROCEED TO SHEET 9 (IF statements with more than two outcomes)