
172
8
8 SPREADSHEETS
Open the file and place the cursor in cell E3. Enter the label ‘Family
availability’. Place the cursor in cell E5 and enter the formula
=IF(D5="None","Not available","Family rooms available").
Do not use absolute referencing in this formula as the reference to cell D5 needs
to change when you replicate the formula. Replicate this formula so it is copied
into cells E5 to E18. Save your spreadsheet as Task_8q.
There are many ways of using the IF function, some of which are shown in
Table 8.4.
In a spreadsheet we wish to enter formulae into cell G1.
Function What it does
=IF(B6="C","Car","Not a car")
Checks the contents of cell B6. If the contents match the letter "C" with
no additional spaces, etc., then cell G1 displays "Car". If cell B6 contains
anything other than the letter "C", then cell G1 displays "Not a car".
=IF(B7=3,"March","Not March")
Checks the contents of cell B7. If the contents are the value 3, then cell G1
displays "March". If cell B7 contains anything other than the value 3, then
cell G1 displays "Not March".
=IF(B7<4,"1st Quarter","")
Checks the contents of cell B7. If the contents are less than the value 4,
then cell G1 displays "1st Quarter". If cell B7 contains a value of 4 or more,
then cell G1 displays a null string (no contents are shown).
=IF(B7<=3,"1st Quarter","")
Checks the contents of cell B7. If the contents are less than or equal to 3,
then cell G1 displays "1st Quarter"; if not, cell G1 displays a null string.
=IF(OR(B7=4,B7=5,B7=6),"2nd
Quarter","")
Checks the contents of cell B7. If the contents are any of the values 4, 5 or
6, cell G1 displays "2nd Quarter"; if not, cell G1 displays a null string.
=IF(AND(B7>3,B7<7),"2nd Quarter","")
Checks the contents of cell B7. If the contents are greater than 3 AND less
than 7, cell G1 displays "2nd Quarter"; if not, cell G1 displays a null string.
=IF(NOT(OR(B7<4,B7>6)),"2nd
Quarter","")
Checks the contents of cell B7. If the contents are NOT less than 4 OR NOT
greater than 6, cell G1 displays "2nd Quarter"; if not, cell G1 displays a null
string.
▲ Table 8.4 Ways of using the IF function
IFS function
The IFS function looks at a number of given conditions and performs a
different operation if one of these conditions is met. If none of the conditions
are met it returns an error message, so careful use of error trapping may be
needed with this function (we will look at error trapping later in this Task). This
is just a more efficient method of nesting IF statements.
Task 8r
Open the file WorkLocation.csv andforeachemployee,incolumnC,identify
where they are working, given that project Alpha is in London, project Beta is in
Milan and project Gamma is in Tunis.
SavethespreadsheetasTask_8r.
Open the file and place the cursor in cell C2. Enter the formula:
=IFS(B2="Alpha","London",B2="Beta","Milan",B2="Gamma","Tunis")
Do not use absolute referencing in this formula as the references to cell B2 need
to change when you replicate the formula. Replicate this formula so it is copied
into cells C3 to C11.