Lab Manual Spreadsheets: Microsoft Excel
Lab Manual Spreadsheets: Microsoft Excel
Lab Manual
SPREADSHEETS
MICROSOFT EXCEL
1
Table of Contents
Lab 1: Excel Basics ......................................................................................................................................... 3
The interface ............................................................................................................................................. 3
Auto‐complete .......................................................................................................................................... 4
Formatting ................................................................................................................................................ 6
Basic calculations ...................................................................................................................................... 7
Lab 2: Charts and Pivot Tables .................................................................................................................... 10
Charts ...................................................................................................................................................... 10
Pivot tables.............................................................................................................................................. 17
Lab 3: Conditionals and Lookup Tables....................................................................................................... 25
Conditional functions .............................................................................................................................. 25
IF functions.............................................................................................................................................. 29
Lookup functions..................................................................................................................................... 35
Lab 4: Conditional Formatting and Lists ..................................................................................................... 39
Conditional formatting............................................................................................................................ 39
Sorting lists.............................................................................................................................................. 47
Filtering lists ............................................................................................................................................ 51
2
Lab 1: Excel Basics
Microsoft Excel is a spreadsheet application that is used for basic data organization, statistical analysis,
graphing data as well as many other uses. In this lab, we will take a look at what makes up an Excel
spreadsheet and the basic uses of it.
The interface
2
1 3
5
4
6
7
3
7. The worksheet toolbar: An Excel file is called a workbook. It consists of a number of spreadsheets
(worksheets). This toolbar allows you to move between the different sheets in a workbook. It also
allows you to create new worksheets, delete existing sheets, and rename sheets.
Exercise 1
1. Enter the data “Sunday” into cell A1 and “Monday” into cell B1.
2. Type in “17/08” into cell E8.
3. Type in “2” into cell I8 and “4” into cell I9.
Auto‐complete
Your worksheet should now look like this:
Lab 1: Excel Basics
5
Exercise 2
1. Auto‐complete cells I8 and I9 all the way to I14.
2. Auto‐complete cell E8 all the way to E12.
Formatting
Excel allows you to format your data so that it shows up in the way you need it to. Let us start with
number formatting. Select cells I8 and I9. If you take a look at the Number group in the Home tab on
the ribbon, you will notice that the current number format is “General”:
Selecting that drop down box shows you some of the available number formats, as shown below.
Lab 1: Excel Basics
6
Select currency from the drop down menu. Now, you will notice that the two numbers have a $ sign
preceding them, and have two decimal places. Let us change the currency symbol to a Euro. Select the
Euro symbol from the currency format menu.
Exercise 3
Modify cells I8 and I9 by removing the 2 decimal places.
Exercise 4
Format cell E8 so that it looks like August 17, 2010.
Lab 1: Excel Basics
7
Press Enter. Excel automatically replaces the formula with the result of the equation.
Now let us calculate the sum of the numbers in I8 and I9. In cell J10, type “=I8+I9”. One other option is
to type in “=”, then select cell I8. After that, type in “+” and then select I9.
Lab 1: Excel Basics
8
Pressing Enter will give you the result of the calculation. Double‐clicking on the cell with the formula
allows you to edit the formula.
Excel has built‐in functions that make your life easier. One of them is the SUM function. In cell J11, type
“=sum(“. Now select both cells I8 and I9.
Pressing Enter gives you the same result as the plus operation we did in cell J10. Try changing the value
in cell I8 and notice how the change is reflected in both formulas.
Exercise 5
1. Open Sheet 2 in your workbook.
2. In cells A1 and A2, type 1000 and 1500 respectively.
Lab 1: Excel Basics
9
Lab 2: Charts and Pivot Tables
Charts
Turning data into charts can help visualize the information at hand. To convey the appropriate message
from your data, you need to select an appropriate type of chart for your data.
Let us start out with creating a simple chart using the chart wizard. Open the file excellab2.xslx. In the
total expenses sheet, you will see a table showing the total expenses accumulated by a company in the
12 months of a particular year. Select the entire table.
Lab 2: Charts and Pivot Tables
10
This is the chart Excel creates:
Lab 2: Charts and Pivot Tables
11
not need a legend, a title for the y‐axis nor data labels. Now that I know what we want, the chart
becomes very easy to customize using Excel’s chart layouts.
Looking at Excel’s built‐in layouts, you will notice that none of them quite satisfy our chart
requirements. Here we have two options. One option is to select one of the layouts and modify it to fit
our needs. For instance, we could pick Layout 6 and simply delete the data labels. The other option
would be to go to the Layout tab in the Chart Tools menu. This tab lets you fine tune the layout of the
chart.
Take a look at the Labels group in the Layout tab. Since we already have a chart title, we do not need to
worry about it. Let us add the x‐axis title. Select Axis Titles, then hover over Primary Horizontal Axis Title,
Lab 2: Charts and Pivot Tables
12
The chart now shows an x‐axis title:
Lab 2: Charts and Pivot Tables
13
Now that the layout of the chart is what we want, let us enter the correct titles. Click the chart title and
replace it with “Total expenses for 2009”. Do the same for the axis title and replace it with “Expenses
($)”.
Now we can play around with the chart colors. Again, Excel allows you to either select one of its predefined
themes or to change the background and colors, one at a time. Select Style 25 from the
Chart Styles group in the Design tab.
Lab 2: Charts and Pivot Tables
14
Your chart now looks like this:
Let’s do a little more formatting. Select the chart area (the box that encompasses the chart title and plot
area). Go to the Format tab and under Shape styles, select Subtle Effect ‐ Purple, Accent 4.
Lab 2: Charts and Pivot Tables
16
Exercise 2
Using the same table (Total Expense sheet), create a 2D pie chart. Instead of showing absolute values, we
would like the chart to show the percentages that each segment makes up as a data label. The month
name should also be part of the label and the legend is not needed. The labels should be at the inside end
of the data points. Make sure the chart has a meaningful title. Adjust the chart size so that all the data
is clearly visible. Give the chart area a black border.
Pivot tables
Lab 2: Charts and Pivot Tables
17
The dialog box that pops up allows you to modify the range of data to be used for the pivot table, and to
choose where the pivot table needs to be placed. Leave everything as is and press the OK button.
Lab 2: Charts and Pivot Tables
18
This is what you should get:
Let us first take a look at what the different field areas are used for. Their usage will become clear
Lab 2: Charts and Pivot Tables
19
At this stage, the pivot table does not look like anything that makes sense. We need to tweak it a little
bit to show the information we need. Notice that all the fields have come under Row Labels, except for
Expense, which is under Values.
Lab 2: Charts and Pivot Tables
21
Now, the pivot table shows the information for only the required expense types.
Lab 2: Charts and Pivot Tables
22
The dialog box allows you to select the calculation type for the data field. Select Average and then press
the OK button.
Lab 2: Charts and Pivot Tables
23
The pivot table now shows the average of expenses instead of the sum.
Exercise 3
Modify the pivot table so that it shows the number of times expenses incurred for each month, per
department and per employee, for all expense types.
Exercise 4
Go to the exercise4 sheet in the excellab2.xlsx workbook. The data in the table shows the population
in Canada by age and sex group for 2009.
a) Calculate the totals for each column and row (hint: try dragging the formula).
a) Format the dates so that they are in the dd/mm/yyyy format.
b) Format the expense amounts so that they show the $ sign (without decimal places).
c) Create a pivot table that shows the total amounts spent on groceries and clothes, by date and
store.
Lab 2: Charts and Pivot Tables
24
Lab 3: Conditionals and Lookup Tables
Conditional functions
One very useful set of built‐in functions in Excel is conditional functions. As the name implies, these
perform certain operations based when a specified condition is satisfied. This is best illustrated through
an example. Open excellab3.xslx and go to the sheet named conditions. Now, let us use Excel to give us
a count of the number of employees in each department.
For this, we use the function COUNTIF. The form of this function is COUNTIF(Range, Criteria). The range
is the data values you would like the count to be performed on, and the criteria are the conditions that
need to be satisfied for a cell to be included in the count.
Let us count the number of employees in the IT department. Type =countif( and then select the range of
cells we would like to count.
Lab 3: Conditionals and Lookup Tables
25
Note that IT was placed between quotation marks, as should any criteria you enter. When you press
Enter, the result of the formula is shown.
Lab 3: Conditionals and Lookup Tables
26
Exercise 1
a) Calculate the number of employees in the Accounting department.
b) Calculate the number of employees with a salary greater than 15000 (remember the quotation
marks around the entire criteria).
Now let us try using a cell address as a criterion. We would like to find the number of employees who have
a salary greater than Reagan’s salary. The only difference here is that to include a cell address in the
criterion; there is a special syntax as shown below.
Lab 3: Conditionals and Lookup Tables
27
SUMIF also lets you define separate ranges for the criterion and the summation. For example, we might
want to calculate the sum of all salaries of the IT department.
Lab 3: Conditionals and Lookup Tables
28
As you can see above, we first provide the formula with the range of values on which the criteria will be
applied. We then enter the criteria, followed by the range which is to be summed up if the criteria apply
to the 1st range.
Exercise 3
a) Calculate the sum of all salaries that are below the average of salaries.
b) Calculate the sum of salaries of the HR and Accounting departments.
c) Using AVERAGEIF, calculate the average of all salaries that are less than or equal to Stacey’s.
IF functions
IF functions or statements allow you to ask the question “is this true or false?” It then allows you to
implement different actions based on the outcome. That is, it allows you to compute two different
outcomes based on whether a certain criterion (logical test) is true or false. The format of an IF
statement is as follows:
=IF(logical test, value if true, value if false).
In excellab3.xslx, open the if statements sheet. The grades shown are for a pass/fail course, with the
passing grade starting at 60. Let us use IF statements to display which students have passed, and which
have failed.
First, start with the logical condition that needs to be evaluated. In this case, a student passes the course
if her/his grade is greater than or equal to 60, say. The symbol >= means greater or equal.
Lab 3: Conditionals and Lookup Tables
29
After we formulate the logical test (the student’s grade is >= 60), enter what we want Excel to display if
this condition was true. In this case, we want Excel to display “Passed”.
Finally, enter the value if the condition is false. The IF function shown below reads: if B2 is greater or
equal to 60, then display Passed; otherwise, display Failed.
Lab 3: Conditionals and Lookup Tables
30
Now, drag the cell with the formula into the rest of the column.
Exercise 4
The instructor for this course would like to reward the students who got a grade strictly above 85. Use if
statements to display “Reward” or “No Reward” beside each student.
Now what happens if this course was not a pass/fail course, rather one with a letter grading scheme?
This requires the use of nested IF statements. Nested if statements allow you to embed IF statements in
Lab 3: Conditionals and Lookup Tables
31
Notice that the logical condition of the IF function is similar to what we had done before: we require the
grade cell to be greater than a certain value. Specifically, if B2>90, the Excel displays the letter mark A. If
this condition is false, or B2 is less than or equal to 90, we need another IF condition in order to determine
the letter grade since values that are less than or equal to 90 can result in different letter marks. For
example, 77 is a B, 65 is a C, and 20 is F. All these values are less than or equal to 90.
Let us complete the entire function:
Lab 3: Conditionals and Lookup Tables
32
Notice that with each new IF statement, we opened up new parenthesis and that at the end we had to
close all of them. Drag the IF statement into the rest of the column.
Lab 3: Conditionals and Lookup Tables
33
The following flowchart depicts how this IF function works.
True Is grade
> 90?
Print “A” False
True Is grade
> 75?
Print “B” False
True Is grade False
> 60?
Print “C” Print “F”
If B2>90, the A is displayed. If this logical condition is false (B2 is less than or equal to 90), a new if function
takes effect: IF (B2>75,”B”,IF(B2>60,”C”,”F”)). In this function, the logical test is B2>75, the value if
true is B, and the value if false is another if function: IF (B2>60,”C”,”F”). Hence, if B2>75 is true, B is
displayed. If not, we need to check the mark if it is a C or an F. If B2>75 is false the last if function takes
effect: IF (B2>60,”C”,”F”). If B2>60, display 60; otherwise, display F.
Lab 3: Conditionals and Lookup Tables
34
Lookup functions
You may have noticed that some of these if statements can get quite long. An easier way to match up
the grades to their corresponding letter grade is to use the LOOKUP function.
The first thing you need to do is to create a lookup table that displays which numerical grades
correspond to which letter grades. This is the grade distribution:
A >=90
B >=80
C >=65
D >=50
F otherwise
Open the lookup sheet.
Now let us put this table into action, using a LOOKUP function.
Lab 3: Conditionals and Lookup Tables
35
The first parameter we give the lookup function is the value to be looked up, which in this case, the
numerical grade. The second input is the lookup table. Now drag the function to the rest of the column.
Lab 3: Conditionals and Lookup Tables
36
we need to fix the lookup table address in the formula. The way this is done is by adding $ as prefixes in
cell addresses. The $ sign before a column name or a row number signifies an “absolute” or fixed
address. When the formula is copied, Excel does not change absolute addresses. To the contrary, the
reference D2 is called a “relative” address. In essence, it is saying lookup the value immediately to the
left of cell E2 (where the lookup function is created) and go from there. So, when the formula is copied
from E2 to E3, D2 will be updated to D3. Lookup tables should be always referenced in an absolute way.
A shortcut to do this is by clicking on F4 right after selecting the lookup table. Now try dragging the
formula again.
Lab 3: Conditionals and Lookup Tables
37
Now it all looks good, and as you can see above, the address of the lookup table was fixed.
Remember:
‐ The lookup table must be in ascending order.
‐ If lookup cannot find the exact match to the value you provided, it will return the result
corresponding to the largest value that is less than or equal to the value you provided.
‐ If the value you are looking for is smaller than the smallest value in the table, an error value will be
returned.
Lab 3: Conditionals and Lookup Tables
38
Lab 4: Conditional Formatting and Lists
Conditional formatting
Conditional formatting allows you to make data trends stand out visually.
Open the file excellab4.xslx and navigate to the condForm sheet. Let us say we would like to quickly
view who has OT (Over Time hours) more than 10 hours.
First, start by selecting your data range:
Lab 4: Conditional Formatting and Lists
39
In the dialog box that pops up, Enter 10. Notice that you can modify the way that the cells are formatted
by choosing the fill and text colors from the drop down list labeled with. For this exercise, leave the
formatting as light red for the fill and dark red for the text. Click the OK button when you are done.
Lab 4: Conditional Formatting and Lists
40
Exercise 1
Highlight the Hours that are in the bottom 20%. Format them so that they have a Yellow Fill with Dark
Yellow Text. (Hint: use Top/Bottom Rules).
Lab 4: Conditional Formatting and Lists
41
The data bars now provide you with a quick relative view of the total amounts employees earn.
Lab 4: Conditional Formatting and Lists
42
value and another to the minimum. The values in between get assigned “in‐between” colors. In
addition, the 3‐color scales assign a color to a selected midpoint. The colors and values assigned to them
can be modified by selecting Manage Rules under the Conditional Formatting header.
You can also delete rules by selecting the cells where you would like to clear the rules, then navigating
to the Clear Rules menu under Conditional Formatting. Click on Clear Rules from Selected Cells.
Exercise 2
After you have cleared the data bars rule from the Total column, apply the Green‐Yellow‐Red color
scale.
Lab 4: Conditional Formatting and Lists
43
As you can see below, Excel assigns the icons based on its own calculations.
Lab 4: Conditional Formatting and Lists
44
means is that Green icons will be assigned to values >= 67 percent between the lowest value (8.5) and
the highest (15). In this case, the minimum value associated with 67 percent is 0.67*(15‐8.5)+8.5. This is
12.9. In other words, Excel calculates these percentages by assigning 100% to the highest value in the
range and 0% to the lowest.
Let us change the type of values to Percentile instead of Percent.
Lab 4: Conditional Formatting and Lists
45
Percentiles do not calculate the percentages within ranges of values. Percentiles are based on the order
of a value among the other values. Values <= the 33 percentile means that red icons will be assigned to
the bottom 4 values. If you are interested in the Math, this is because 0.33*13 (the number of values) =
4.29.
What you need to understand about this is that percentages are calculated relative to the lowest and
highest values when percentiles are calculated based on the position of a value in the ordered list of
Lab 4: Conditional Formatting and Lists
46
Sorting lists
Sorting a list or sorting an entire table are both functions that will most likely come up whenever you are
doing data analysis. You can easily sort data in alphabetic, numeric, or even chronological order.
Let us try sorting our table by the ascending alphabetic order of the names of the employees. Select the
range of names in the table. Then in the Home tab, under the Editing group, select Sort A to Z.
A warning message pops up:
Lab 4: Conditional Formatting and Lists
47
Exercise 5
Sort the table through the Hours column, from largest to smallest.
Excel also lets us perform more complicated sorting. Let us try to sort the table by the cell icons of the
Rate column.
Lab 4: Conditional Formatting and Lists
48
The custom sort dialog box pops up.
Lab 4: Conditional Formatting and Lists
49
Now we can add another level of sorting so that the red icon is at the bottom. Click on the Add Level
button in the dialog box. Select Rate and Cell Icon again. This time, make sure the red icon is ordered on
the bottom, and then click the OK button.
Lab 4: Conditional Formatting and Lists
50
This is what your table should look like:
Exercise 6
Use custom sort to sort the table in the descending order of the OT Rate and then in ascending order of
the names of the employees.
Lab 4: Conditional Formatting and Lists
51
Notice that there is now an arrow next to the Region header. This arrow means that a filter can be
applied to this column, but no filters are currently being used.
Lab 4: Conditional Formatting and Lists
52
Click the arrow next to the Region header. Let us only show the data for sales in the East region. One
way to do this is to deselect NW and SW as shown below.
Now, only the rows showing information from either the NE or SE are shown. Notice the button next to
the region header has changed to a filter icon indicating that a filter has been applied.
Lab 4: Conditional Formatting and Lists
53
There is another way by which the same result can be achieved. First let us remove the applied filter.
Click on the button next to Region and select “Select All”. Click the OK button.
Now that we can see our original data, let us add a new filter. Select the arrow next to Region and move
the mouse cursor over Text Filters. Choose Ends With.
Lab 4: Conditional Formatting and Lists
54
In the dialog box that pops up, enter E as shown below. This will only show the rows in which the Region
ends with an E. Click on the OK button.
Lab 4: Conditional Formatting and Lists
55
5
Exercise 7
Create a new filter that only shows the data for salespeople who have joined after May 2004,
and
before or during May 2008. Filter this further so that it only shows the ones who have sales less
56