You are on page 1of 3

SIMPLE AND NESTED IF STATEMENTS EXPLAINED

Use the payroll workbook provided or create your own workbook for this exercise

Assumptions:
1. You are using the same spreadsheet I provided you.
2. If not then your column headers must coincide with mine

The simple if statement has the function =IF(condition, true, false). An if statement will always
result in one of two outcomes; if is a conditional statement or expression that always result in a
true or false, yes or no, in or out, 0 or 1, M or F, one of two outcomes. Example IF (sex= ‘M’
THEN he is a Male ELSE she is a Female). Do you agree with the sex logic so far? If you do not
then please go over the paragraph or call your friend to help you. Okay, let us look at a situation
where a hermaphrodite (neither Male nor Female) also exist. It means now we have three
conditions; Male (M), Female (F) and hermaphrodite (H).

To take care of the hermaphrodite situation we must manipulate the above if statement to take
care of the three situations of M, F & H simultaneously. So our earlier if statement, taking care
of only two situations, constructed as IF (sex= ‘M’ THEN he is a Male ELSE she is a Female)
has to change; If sex is ‘M’ THEN we ascribe male to the person. We are now left with the
alternate ELSE outcome but with two (2) sexes of ‘F’ and ‘H’ to cater for. How do we resolve
this situation?

We resolve by modifying the simple if statement into a nested if statement. Let us construct
another if statement, within the existing if statement. The new if statement becomes IF (sex=
‘M’ THEN he is a Male ELSE IF (sex= ‘F’ THEN she is a Female ELSE she is
hermaphrodite)). Voila.

Now let’s do some exercises to further understand if statement. In Cell H3 type any number and
press enter. In cell I3 type =If (H3<10, “less than 10”, “more than 10"). Press enter and less
than 10 or more than 10 will appear in cell I3. The statement means IF the content of H3 is less
than 10 THEN print less than 10 ELSE print more than 10. Keep entering the numbers 9, 4, 11,
14 while at the same time watching the outcomes. Were you satisfied with the results? Perfect.
Actually, not perfect because the logic does not take care of situation where the number in cell
H3 is equal to 10. Now enter 10 in cell H3 and examine the output. Is what you entered more
than 10? You entered 10 and it is not more than 10 so it means the logic in the If statement is not
correct. It is wrong.

The logic in the above if statement If (H3<10, “less than 10”, “more than 10") is that if the
number is not less than 10 then it is assumed to be greater than 10, ignoring one nore important
condition - the equality condition. To correct it we have to convert out if statement into a nested
if statement: =If (H3<10, “less than 10”, If (H3>10, “more than 10”, “equal to 10")). The
above resolves the problem and takes care of the less than, greater than and equal to condition.
With the above knowledge, and exercises involving VLookup lets begin work on our payroll.
Type the following contents in the respective cells:
=VLOOKUP(B3,Salary_Scale,2,0) in C3, where Salary_Scale is the name given to the salary table
=C3*5% in D3
=C3*10% in E3
=C3*VLOOKUP(F3,Rent_Allowance,2,0) in G3, where Rent_Allowance is the name for rent table
=C3-D3 in H3
=IF(C3<650,0.01*C3, 111) in I3

=IF(C3<650,0.01*C3,IF(C3<800,0.03*C3, 222))

=IF(C3<650,0.01*C3,IF(C3<800,0.03*C3,IF(C3<1220,0.05*C3, 333)))

=IF(C3<650,0.01*C3,IF(C3<800,0.03*C3,IF(C3<1220,0.05*C3,IF(C3<2000,0.08*C3, 444))))

=IF(C3<650,0.01*C3,IF(C3<800,0.03*C3,IF(C3<1220,0.05*C3,IF(C3<2000,0.08*C3,IF(C3<3000,0.1*C3, 555)))))

=IF(C3<650,0.01*C3,IF(C3<800,0.03*C3,IF(C3<1220,0.05*C3,IF(C3<2000,0.08*C3,IF(C3<3000,0.1*C3,0.15*C3)))))

=C3+E3+G3 in J3
=J3-D3-I3 in K3

You might also like