Using If Statement in ExcelA
Using If Statement in ExcelA
To use functions, you need to understand reference operators. Reference operators refer to a cell
or a group of cells. There are two types of reference operators: range and union.
A range reference refers to all the cells between and including the reference. A range reference
consists of two cell addresses separated by a colon. The reference A1:A3 includes cells A1, A2,
and A3. The reference A1:C3 includes cells A1, A2, A3, B1, B2, B3, C1, C2, and C3.
A union reference includes two or more references. A union reference consists of two or more
numbers, range referneces, or cell addresses separated by a comma. The reference
A7,B8:B10,C9,10 refers to cells A7, B8 to B10, C9 and the number 10.
Understanding Functions
Functions are prewritten formulas. Functions differ from regular formulas in that you supply the
value but not the operators, such as +, -, *, or /. For example, you can use the SUM function to
add. When using a function, remember the following:
Enclose arguments within parentheses. Arguments are values on which you want to perform the
calculation. For example, arguments specify the numbers or cells you want to add.
=SUM(2,13,A1,B2:C7)
In this function:
After you type the first letter of a function name, the AutoComplete list appears. You can
double-click on an item in the AutoComplete list to complete your entry quickly. Excel will
complete the function name and enter the first parenthesis.
EXERCISE 1
Functions
As you learned in Lesson 2, you can also calculate a sum by using the AutoSum button .
Calculate an Average
You can use the AVERAGE function to calculate the average of a series of numbers.
In Microsoft Excel, you can use the AutoSum button to calculate an average.
1. Move to cell C6.
2. Choose the Home tab.
3. Click the down arrow next to the AutoSum button .
4. Click Average.
You can use the MIN function to find the lowest number in a series of numbers.
1. Move to cell A7.
2. Type Min.
3. Press the right arrow key to move to cell B7.
4. Type = MIN(B1:B3).
5. Press Enter. The lowest number in the series, which is 12, appears.
Note: You can also use the drop-down button next to the AutoSum button to calculate
minimums, maximums, and counts.
You can use the MAX function to find the highest number in a series of numbers.
You can use the count function to count the number of numbers in a series.
1. Move to cell A9.
2. Type Count.
3. Press the right arrow key to move to cell B9.
4. Choose the Home tab.
5. Click the down arrow next to the AutoSum button .
6. Click Count Numbers. Excel places the count function in cell C9 and takes a guess at
which cells you want to count. The guess is incorrect, so you must select the proper cells.
7. Select B1 to B3.
8. Press Enter. The number of items in the series, which is 3, appears.
You can use Microsoft Excel to fill cells automatically with a series. For example, you can have
Excel automatically fill your worksheet with days of the week, months of the year, years, or
other types of series.
EXERCISE 2
1. Click the Auto Fill Options button. The Auto Fill Options menu appears.
2. Choose the Copy Cells radio button. The entry in cells A1 and B1 are copied to all the
highlighted cells.
3. Click the Auto Fill Options button again.
4. Choose the Fill Series radio button. The cells fill as a series from Sunday to Saturday
again.
5. Click the Auto Fill Options button again.
6. Choose the Fill Without Formatting radio button. The cells fill as a series from Sunday to
Saturday, but the entries are not bolded.
7. Click the Auto Fill Options button again.
8. Choose the Fill Weekdays radio button. The cells fill as a series from Monday to Friday.
Some of the entries in column B are too long to fit in the column. You can quickly adjust the
column width to fit the longest entry.
1. Move your mouse pointer over the line that separates column B and C. The Width
Indicator appears.
After you complete the remainder of the exercise, your worksheet will look like the one shown
here.
Fill Times
Fill Numbers
1. Grab the fill handle and drag with your mouse to highlight cells D1 to D14. The number
1 fills each cell.
2. Click the Auto Fill Options button.
3. Choose the Fill Series radio button. The cells fill as a series, starting with 1, 2, 3.
1. Go to cell E1.
2. Type Lesson 1.
3. Grab the fill handle and drag with your mouse to highlight cells E1 to E14. The cells fill
in as a series: Lesson 1, Lesson 2, Lesson 3, and so on.
Lesson 2
Using If Statements in Excel
Conditional logic(IF) is used quite frequently in modern spreadsheets. But let's start by asking
What is Conditional Logic?
Conditional Logic
For our purposes, conditional logic is two words - "IF" and "Then". You use conditional logic a
the time in your daily life, without realising it. You might say to yourself, "IF I eat this delicious
cream cake THEN my diet will be ruined." You're using conditional logic to make a decision: IF
do this THEN that will happen. Some more examples:
Those are all example of conditional logic. Excel also uses the IF word for conditional logic. Y
can test what is in a cell, and say what should happen if it is one value rather than another. Fo
example, suppose cell A1 has the number 6 in it. In cell A2, you can enter an IF function to te
whether cell A1 is above 5 or below 5. IF it is above 5 THEN one thing happens; IF it is below
THEN another thing happens.
So the IF function takes three arguments: logical test, value if true, value if false. Let's brea
those three arguments down a little more:
Logical Test:
This is what you want to test for. In our example, we wanted to test whether cell A1 is
greater than or less than 5. Excel uses this symbol > for greater than and this symbol
for less than. So for the first argument, we would put A1 > 5
Value If True:
This is the THEN part of the IF statement. Excel needs to know what you want to
happen IF your condition is met. You can put in text surrounded by quotes, or another
formula.
Value If False:
You also need to say what should happen IF your condition is not met.
Let's clarify all this with a spreadsheet example. So, start a new spreadsheet and do the
following:
But click inside cell A1 and change the number 6 to the number 4. Then press the return key o
your keyboard. Excel should put Less than Five in cell B1. Now put the number 5 in cell A1 an
see what happens.
Nothing happened, right? That's because the IF function is very precise. You didn't tell Excel
what to do if the number equalled 5.
To get round this, we can use the Greater Than ( > ) symbol and the Equal symbol together.
Like this:
A1 >= 5
That says "A1 greater than or equal to 5". When we amend our function, it looks like this:
You can also test to see if something is Less Than ( < ) or Equal to. You could use this for th
formula:
You can even test for Not Equal To. Just join the Less Than (<) symbol to the Greater Than (
symbol. Like this:
So to sum up: after typing IF you tell Excel what you want to test for. Then you say what shou
happen if the condition is true. Then you say what should happen if the condition is false.
IF Statements in Formulas in Microsoft Excel
The first part of the IF statement is called a logical test, which is also often referre
to as a condition.
Tip. Note that all “text” is surrounded by quotes when used in formulas.
There are a few exceptions, such as True and False.
We like to think of the commas that separate the 3 arguments as words. The first
comma means “give me”, and the second means “otherwise, give me”. So if we
wrote the above formula in English instead, it would read like this:
If we don’t provide the third part of the argument, we simply get the “answer”
returned to us: A2 is not greater than 60, so our condition or logical test is FALSE
Tip. You may only use 7 nested IF statements. That means 8 IFs can be in
your formula; 7 being nested inside the first. Even in Excel 2003, there is
no indication that the problem with the formula is too many IFs. If you
have a requirement for more than 7, use VLOOKUP, instead.
Let’s break down the formula, IF by IF:
=IF(A1>60,”D”
IF(A1>70,”C”
IF(A1>80,”B”
IF(A1>90,”A”
“F”
IF with AND
Let’s suppose that a sales bonus is based on having made at least 20 sales call,
and having made at least 15,000 in sales. We must check both conditions, using a
AND statement.
IF with OR
Now, let’s use IF with an OR statement. In this case, a sales bonus is based on
having made at least 20 sales calls, OR having made at least 15,000 in sales. If
either condition is met, the bonus is given.
In the last issue of Techtrax, I taught you how to do simple IF statements based on one condition and on
value if true or false. I promised I would show you how to do this with multiple conditions and multiple
true/false values, so that’s what I’m going to do now.
For this, let’s use some new data. Open a blank workbook in Excel and enter this data:
A B C D E
1 Name District Sales Emp. Yrs Job Level
2 Linda East $20,000.00 2
3 Joe West $42,302.00 9
4 Bill East $53,001.00 3
5 Mary South $12,000.00 12
6 Mark South $ 2,050.00 6
7 John North $9,000.00 0
8 Ted East $40,000.00 4
Let’s pretend this is data which shows your salespeople’s district, annual sales, and number of years
employed by your company. Now, let’s suppose you want a formula in column E that will assign a job
level based on two different criteria: Salespeople who have been employed for more than 5 years AND
have annual sales of more than $10,000 should be assigned a job level code of 2, and all others should
have a job level code of 1. To include two criteria, when both criteria must be met, you must nest an
AND function within your IF statement. Put this formula in cell E2:
=IF((AND(D2>5,C2>10000)),2,1)
Then, grab cell E2 by its fill handle and drag it down to cell E8 to “relatively” copy it to the rest of the
cells in column E.
You see this formula uses a nested AND function for its “logical test”. The AND function will decide i
both conditions are true. Remember, the IF function’s second and third arguments return a “value if tru
and a “value if false”, so if the AND function returns a “true”, a 2 will be placed in the cell and if the
AND function returns a “false”, a 1 will be placed in the cell. Excel will look into the deepest nested
function first, then work it’s way out, so the first thing it does is determine the result of the AND
function, then it goes out to the IF function and performs that, based on the results of the AND function
This formula, if entered correctly, should show job level code 2 for Joe and Mary only, because they ar
the only two who have worked for the company more than five years AND had annual sales greater tha
$10,000.
Similarly, you can use a nested OR function if you want a job level code of 2 to be applied if an
employee meets EITHER criterion, instead of both criteria. A nested OR function works the same way
an AND function, except it will return the 2, if ANY of the criteria are met, instead of requiring that AL
criteria are met.
=IF((OR(D2>5,C2>10000)),2,1)
In this case, everyone is assigned a job level 2 except John, because he is the only one who did not mee
either criterion, since he has not worked for the company for more than 5 years OR had annual sales
greater than $10,000.
You can use more than two criteria in nested ANDs and ORs. Simply separate them by commas.
These examples work great when there are only two job levels, but what if there are more than two? In
this case, you will have more than two criteria and more than one value if true and value if false.
Let’s say we want to assign a job level 3 if the employee meets BOTH criteria above, a job level 2 if th
employee meets EITHER criteria above, and a job level 1 if the employee doesn’t meet any of the crite
above.
=IF((AND(D2>5,C2>10000)),3,(IF((OR(D2>5,C2>10000)),2,1)))
Notice what we are doing here is basically nesting one IF statement within another. However, though w
have two different logical tests and two different values if true, we only have one value if false. You ca
nest up to 7 IFs in one formula, so that means you can return up to 8 different results (7 different values
true and one value if false).
You can also nest multiple IFs if you want different results based on different values in the same cell. F
this example, let’s say all of the employees in the East district will be assigned a job level 4, the West
ones will be job level 3, the North ones will be job level 2, and the ones in the South will be job level 1
Our formula would look like this:
=IF((B2="East"),4,IF((B2="West"),3,IF((B2="North"),2,IF((B2="South"),1,""))))
Note that the value if false is “”, which tells Excel to leave the cell empty if no match is found in colum
B for that row. If you delete the contents of any cell in column B or change it to anything other than Ea
West, North, or South, you will see the corresponding cell in column E would now be empty. Rememb
you must have something in your third argument (value if false) or Excel will simply enter the text
“FALSE” into that cell if it does not find a match.
I think I’ve given you enough information now, so you can build pretty extravagant IF statements. Just
remember that limit of seven nested IFs though, because there is no way to increase this using an IF
statement. However, when you really need more than eight conditions, there are other functions that wi
serve you better than Nested IFs. One set of functions are the LOOKUP functions and I will cover them
in a later article.
Are we having fun yet? I am, and I hope you are too.