0% found this document useful (0 votes)
18 views

Using If Statement in ExcelA

This document discusses Excel functions and conditional logic. It provides examples of using functions like SUM, AVERAGE, MIN, MAX and COUNT to perform calculations on cell ranges. It also demonstrates using the IF function to perform conditional checks on cell values and return different results based on the check.

Uploaded by

yahelag524
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Using If Statement in ExcelA

This document discusses Excel functions and conditional logic. It provides examples of using functions like SUM, AVERAGE, MIN, MAX and COUNT to perform calculations on cell ranges. It also demonstrates using the IF function to perform conditional checks on cell values and return different results based on the check.

Uploaded by

yahelag524
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Excel Functions

Lesson 1: Creating Excel Functions, Filling Cells, and Printing


By using functions, you can quickly and easily make many useful calculations, such as finding
an average, the highest number, the lowest number, and a count of the number of items in a list.
Microsoft Excel has many functions that you can use.

Using Reference Operators

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:

Use an equal sign to begin a formula.

Specify the function name.

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.

Use a comma to separate arguments.

Here is an example of a function:

=SUM(2,13,A1,B2:C7)

In this function:

The equal sign begins the function.


SUM is the name of the function.

2, 13, A1, and B2:C7 are the arguments.

Parentheses enclose the arguments.

Commas separate the arguments.

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

The SUM function adds argument values.

1. Open Microsoft Excel.


2. Type 12 in cell B1.
3. Press Enter.
4. Type 27 in cell B2.
5. Press Enter.
6. Type 24 in cell B3.
7. Press Enter.
8. Type =SUM(B1:B3) in cell A4.
9. Press Enter. The sum of cells B1 to B3, which is 63, appears.
Alternate Method: Enter a Function with the Ribbon

1. Type 150 in cell C1.


2. Press Enter.
3. Type 85 in cell C2.
4. Press Enter.
5. Type 65 in cell C3.
6. Choose the Formulas tab.
7. Click the Insert Function button. The Insert Function dialog box appears.
8. Choose Math & Trig in the Or Select A Category box.
9. Click Sum in the Select A Function box.
10.Click OK. The Function Arguments dialog box appears.

12.Type C1:C3 in the Number1 field, if it does not automatically appear.


13.Click OK. The sum of cells C1 to C3, which is 300, appears.
Format worksheet

1. Move to cell A4.


2. Type the word Sum.
3. Select cells B4 to C4.
4. Choose the Home tab.
5. Click the down arrow next to the Borders button .
6. Click Top and Double Bottom Border.

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.

1. Move to cell A6.


2. Type Average. Press the right arrow key to move to cell B6.
3. Type =AVERAGE(B1:B3).
4. Press Enter. The average of cells B1 to B3, which is 21, appears.

Calculate an Average with the AutoSum Button

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.

5. Select cells C1 to C3.


6. Press Enter. The average of cells C1 to C3, which is 100, appears.

Find the Lowest Number

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.

Find the Highest Number

You can use the MAX function to find the highest number in a series of numbers.

1. Move to cell A8.


2. Type Max.
3. Press the right arrow key to move to cell B8.
4. Type = MAX(B1:B3).
5. Press Enter. The highest number in the series, which is 27, appears.

Count the Numbers 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.

Fill Cells Automatically

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

Fill Cells Automatically

The following demonstrates filling the days of the week:

1. Click the Sheet2 tab. Excel moves to Sheet2.


2. Move to cell A1.
3. Type Sun.
4. Move to cell B1.
5. Type Sunday.
6. Select cells A1 to B1.
7. Choose the Home tab.
8. Click the Bold button . Excel bolds cells A1 to B1.
9. Find the small black square in the lower-right corner of the selected area. The small black
square is called the fill handle.
10.Grab the fill handle and drag with your mouse to fill cells A1 to B14. Note how the days
of the week fill the cells in a series. Also, note that the Auto Fill Options button appears.
Copy Cells

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.

Adjust Column Width

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.

2. Double-click. The Column adjusts to fit the longest entry.

After you complete the remainder of the exercise, your worksheet will look like the one shown
here.

Fill Times

The following demonstrates filling time:

1. Type 1:00 into cell C1.


2. Grab the fill handle and drag with your mouse to highlight cells C1 to C14. Note that
each cell fills, using military time.
3. Press Esc and then click anywhere on the worksheet to remove the highlighting.
To change the format of the time:

1. Select cells C1 to C14.


2. Choose the Home tab.
3. Click the down arrow next to the number format box . A menu appears.
4. Click Time. Excel changes the format of the time.

Fill Numbers

You can also fill numbers.

Type a 1 in cell D1.

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.

Here is another interesting fill feature.

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:

IF I buy this lovely coat THEN I will look beautiful


IF I watch one programme THEN I can tape the other

IF I win the lottery THEN I will be happy

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.

The correct format to use for the IF function is this:

IF(logical_test, value_if_true, value_if_false)

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:

 Click inside cell A1 and enter the number 6


 Press the return key on your keyboard
 Widen the B column of your spreadsheet. Make it nice and big.
 Click inside cell B1
 Click inside the formula bar
 Enter the following formula:

=IF(A1 > 5, "Greater than Five", "Less than Five")

 Press the return key on your keyboard


 Your spreadsheet should look like this one below:
It's important you get all the syntax right in your IF function. In other words, don't forget the
commas, and the double quote marks around text.

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:

=IF(A1 >= 5, "Greater than or Equal to Five", "Less than Five")

You can also test to see if something is Less Than ( < ) or Equal to. You could use this for th
formula:

=IF(A1 <= 5, "Less than or Equal to Five", "Greater than Five")

You can even test for Not Equal To. Just join the Less Than (<) symbol to the Greater Than (
symbol. Like this:

=IF( A1 <> 5, "Not 5", "Is 5")

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

A simple example of an IF statement is giving grades for percentages. We’ll


assume that our percentage is in cell A2, and our formula resides in cell B2.

An IF statement has at least 3 parts called arguments. When you type an IF


statement, the tool tip automatically appears to tell you the 3 arguments required

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 the value in cell A2 is greater than 60, give me a B, otherwise give me an A.

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 the value in A1 is greater than 60, put a D in cell B2.

 IF(A1>70,”C”

If the value in A1 is greater than 70, put a C in cell B2.

 IF(A1>80,”B”

If the value in A1 is greater than 80, put a B in cell B2.

 IF(A1>90,”A”

If the value in A1 is greater than 90, put an A in cell B2.

 “F”

Otherwise—if none of the above conditions are met—put an F in cell B2.

Combining IF with other formulas.

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.

IF with OR and AND

Imagine that employees with perfect attendance become a member of an exclusiv


employee's club. When this occurs, they're given special consideration on bonuses
So, in this case, if they're a member OR they sell more than 15,000 and make at
least 20 sales calls, they receive the bonus.

Excel IF Statements, Part II: Nesting Functions

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.

Put this one in E2 now and copy it down to E8:

=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.

Put this formula in E2 and copy it down to E8

=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.

You might also like