Excel Lab Manual - January 2013 PDF
Excel Lab Manual - January 2013 PDF
Excel Lab Manual - January 2013 PDF
Microsoft Excel
Spreadsheets
1
Peeking into Computer Science | Excel Lab Manual
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
Lab 5: Drop-Down Lists and Dynamic Charts .............................................................................................. 57
Drop-down lists ....................................................................................................................................... 57
OFFSET function ...................................................................................................................................... 61
Dynamic charts........................................................................................................................................ 65
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
4
6
7
s
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:
Now, we want to select both cells A1 and B1 together. To do this, click A1 and without releasing the
mouse button, move the mouse over cell B1. Now there should be a rectangle around both cells as
shown below.
This is what your spreadsheet should look like when you release the mouse button:
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.
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.
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.
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.
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.
You may need to drag the corner of the chart to make it larger so that all the months are clearly visible
on the y-axis. The chart needs some tweaking. First, we need to decide what extra information we want
the chart to show. We want this chart to have a meaningful title and show a title for the x-axis. We do
Looking at Excels 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,
and select Title Below Axis.
Exercise 1
Remove the legend through the Labels group in the Layout tab. If needed, adjust the chart size so that
all the data are clearly visible.
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.
Lets 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.
Now, select the plot area (the area that includes the chart ONLY) and select Colored Outline - Dark 1.
Pivot tables
Let us first take a look at what the different field areas are used for. Their usage will become clear
The pivot table menu to the right allows you to select the fields you want to add to the table. Select all
of the fields by clicking their respective checkboxes.
Now assume that we only want the information for Travel and Social expenses. Click on the drop-down
field next to Expense type, and then check the Select Multiple Items checkbox. After that, deselect the
Expense types we do not need and click OK.
You can also filter column and row labels in the same way. Excel pivot tables allow for different
calculations of the data value. Currently, the Expenses are being summed up. Let us modify this so that
the table shows the average of all expenses.
In the pivot table field list (to the right of the screen), click on Sum of Expenses and select Value Field
settings from the menu.
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 your 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).
Exercise 5
Go to the exercise5 sheet in your workbook.
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.
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.
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 Reagans salary. The only difference here is that to include a cell address in
the criterion; there is a special syntax as shown below.
Exercise 2
a) Calculate the number of employees who are NOT in the IT department. (hint: the not equal sign is
<>)
b) Calculate the number of employees with a salary greater than or equal to Alexis, and less than
Treys. Remember to use cell addresses. (Hint: use two countif operations.)
SUMIF works in almost the same way as COUNTIF, except it returns the sum instead of the count. For
instance, let us calculate the sum of all salaries greater than 15000.
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 Staceys.
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:
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.
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.
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
>90 A
>75 B
>60 C
otherwise F
Nested IF statements are done by replacing the value if false or the value if true in the function with a
new IF statement.
True Is grade
> 90?
Print A False
True Is grade
> 75?
Print B False
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.
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
Now let us put this table into action, using a LOOKUP function.
As you can see, we received plenty of error values. Double-clicking one of those values will show you the
problem. When we dragged the formula, the address of the lookup table was incremented. Therefore,
A shortcut to do this is by clicking on F4 right after selecting the lookup table. Now try dragging the
formula again.
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.
In the lookup exercise sheet, fill in the colors corresponding to the given frequencies using the lookup
function.
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.
Select the range of cells under the Total heading. Click on the Conditional Formatting button and
navigate to the Data Bars menu. Select the Purple Data Bar button.
Using color scales also gives you a similar result as data bars. Both features allow you to get a quick view
of how your data values compare to one another. The 2-color scales assign one color to the maximum
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.
The final aspect of conditional formatting we will cover is icon sets. When using icon sets, each cell is
provided with an icon depending on its value. There are no gradients in icon sets.
Let us format the Rate column using icon sets. Select the cells in the Rate column and apply the 3 traffic
lights (rimmed) formatting to them, as shown below.
If you want to change the way that the icons are assigned, you need to edit the rule (Manage Rules). As
you can see below, Excel is currently assigning the Green icon to values >= the 67 percent. What this
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
values.
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.
What this message is telling us is that with the current selection, only the names column will be sorted.
The data in the rest of the table will not be sorted. This is why we need to select the Expand the
selection radio button. This will allow the entire table to be sorted according the alphabetic order of
the names. Press the Sort button. The entire table has now been sorted.
Excel also lets us perform more complicated sorting. Let us try to sort the table by the cell icons of the
Rate column.
Select Rate as the Sort by column, and then select for it to be sorted on Cell Icon. The order menu now
shows the three icons used in the Rate column. Let us ask for the green icon to be placed on top, as
shown below.
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.
One obvious use for filters here is to view the sales information of only a few regions of interest. Let us
see how this can be done.
Start by selecting the Region column. Under the Home tab and in the Editing Group, select the Sort and
Filter button. Select Filter from the menu.
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.
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.
Now let us remove the filter by clicking on the button next to Region and selecting Clear Filter from
Region from the menu.
Drop-down lists
Drop-down lists are useful in making data entry easier and faster by limiting the number of options to
pre-defined items.
Open the file excellab5.xslx and navigate to the dropdown sheet. The sheet shows a partial table of
students in a class. We would like to limit the possible valid entries into the major column.
First, we need to create a list of all valid majors that will be accepted. Here are a few that one can think
of. Feel free to add your own major if it is not in the list.
Nex,t we need to name our list. Select the list of majors that was created. Go to the Name Box at the left
of the formula bar (shown in a red square below) and type in an easy to remember, descriptive name of
the list, such as ValidMajors.
You can also ask Excel to show an input message describing to users what they need to do. Go to the
Input Message tab and enter an appropriate title and input message:
Now when you click on a cell in the Major column, you get an arrow indicating a drop-down list is
available, as well as the input message we had provided. Try entering a major that is not on the list. You
will see an error message.
Exercise 1
Create a drop-down list for the Gender field. The list should show a warning message on invalid data
entry. No input message is necessary.
OFFSET function
The OFFSET function allows us to start somewhere in the spreadsheet, move in any direction in order to
locate a cell or a range of adjacent cells, and return the value of this cell or a set of values for the range
of cells. The general syntax for this function is:
where:
Let us understand how to use the OFFSET function through an example. Open the dynCharts1 sheet in
excellab5.xlsx. In an empty cell, type =OFFSET(A2, 1, 1, 1, 1) and press Enter.
Try this one: =OFFSET(B5, -3, -1). Starting at cell B5, move 3 rows up and 1 column left. The size of the
returned data is also one cell (since height and width are omitted). The offset is A2 and the value
returned by this function is Jan.
In order to specify a height or a width that is greater than 1, the OFFSET function must be used in
another Excel function, such as SUM or AVERAGE. If you attempt to use it on its own, you will get an
OFFSET(A1, 1, 1, 5, 1) refers to a range of adjacent cells, starting at A1, moving one row down and one
column right this will take us to cell B2. B2 is the top left corner of the required range of values. The
range of cells from B2 spans 5 rows and 1 column. Recall that height and width must always be positive.
Hence, OFFSET(A1, 1, 1, 5, 1) returns B2:B6 or all the average temperature values in the sheet.
Now, use OFFSET in a SUM function and type the formula: =SUM(OFFSET(A1, 1, 1, 5, 1)). Here we are
adding all the temperature values together.
COUNTA is a count function which counts all non-empty cells in a range. We can use it to count all non-
empty values in Column B as such: COUNTA($B:$B). Our new formula is:
=SUM(OFFSET(A1,1,1,COUNTA($B:$B)-1,1))
The range of the OFFSET starts at A1, moving one row down and one column right. That is, the top left
corner of the required range of cells is B2. B2 contains the first temperature value. The height of the
The returned value of the SUM function is 0, the 5 temperatures in column B cancel each other.
Go to the Formulas tab and under the Defined Names group and click on Define Name.
Enter the name, Months. In Refers to, type in the formula that refers to the Months column as shown
below. Type carefully. If you want to check if the range you entered is correct, click in the comments
field then back in the Refers to field. The range should be highlighted in your worksheet. When you are
done, press OK.
Note that a cell address can be prefexed by the sheet name in which the cell is contained followed by
the exclamation mark (!). For instance. dynCharts!$A$2 referes to cell A2 in dynCharts. The address
A$2$ is absulote (fixed).
If you need to view or modify the names in your worksheet, click on the Name Manager in the Defined
Names group.
Now that our formulas are ready, we can create the chart. In the Insert tab, under the Charts group,
select 2D line. Make sure no cells are selected while you are doing this. A blank chart is created. Right-
click the chart and click on Select Data.
We now need to decide which column we would like to see on the vertical axis and which we would like
on the horizontal one. Let us place the temperatures in the vertical axis.
The Series name is the name of the vertical (y) axis values. In this case, it is cell B1. The series values are
the Temps formula we created. To refer to this formula, you must first type in the sheet name it was
Now press the Edit button under Horizontal (Category) Axis Labels.
Next, on the Select Data Source dialog box, press the OK button. Your chart should look like this:
Exercise 4
Sheet dynChartsEx shows a table that shows where money is being spent. Create a pie chart which
shows how the money is spent. The chart should be updated automatically whenever a new expense is
Open excellab6.xslx and navigate to the comboBox sheet. Under the Developer tab, in the Controls
group, press the Insert button, and then select Combo Box from the menu.
Next, drag the cursor and draw the combo box onto your sheet.
In the control tab, place the cursor in the Input Range field, then select the A2 to A5 from the sheet (or
just enter the cell references yourself). The data in these cells will populate the combo box.
The cell link is the cell in which the result of the the combo box selection will be displayed. Select any
empty cell in the sheet . We are going to select cell I3 as the cell link. When you are done, press the OK
button.
Try the combo box. Notice how cell I3 changes to reflect the index of the selected item in the combo
box.
Exercise 2
Create another named variable called SelectedQuiz, which points to the quiz name currently selected in
the combo box (hint: use the combo box cell link and OFFSET).
Exercise 3
Create a named variable called Students that points to the names of the students in the table. The list
should be updated when a new student is added (hint: just like counting cells in a column is done
through COUNTA($B:$B), counting cells in a row can be achieved by the formula COUNTA($1:$1)).
Exercise 4
Create a named variable called SelectedGrades. This should refer to the array of grades of the selected
quiz selected in the combo box.
After you are done with the above exercises, it becomes easy to create the chart. Without any range of
cells being selected, create an empty 2D column chart. Right-click the chart and select Select Data from
the menu.
A good idea for the series name would be the name of the current quiz selected. The series values
should be the selected grades. Do not forget to enter the name of the sheet first, as shown below. Click
OK when you are done.
Obviously, the horizontal axis should contain the names of the students. Click the Edit button under the
Horizontal (Category) Axis Labels and mention the Axis label range as shown below.
Repeat this three more times, changing the quiz number each time.
Right-click the 1st check box and select Format Control. Just like we did with the combo box control, we
need to set the cell link for each check box. This cell will display TRUE or FALSE values, depending on
whether the box is checked or not.
At this point, we need to create a named variable for each of the check boxes. Click on the Define Name
button in the Defined Names group under the Formulas tab.
The first formula we are going to enter is for whether or not we need Excel to plot Quiz 1 values.
Obviously, since this requires TRUE/FALSE decision making, we need to use If statements. The if
statement shown below checks the cell link for the 1st check box, if it is true, it returns the quiz grades
for quiz 1, otherwise it returns a 0.
We also need to create named variables for the series titles. The if statement returns blank if the box is
unchecked.
Exercise 6
Create named variables for the rest of the series titles.
Insert a blank 2D line chart into your sheet. Just for the time being, make sure all your check boxes are
checked; Excel will return error messages otherwise. Right-click on the chart area and click on Select
Data. Press the Add button under the Legend Entries header. The series name here is the Quiz 1 title
variable. The values are the Quiz 1 values. Remember that both will return blanks or zeroes if the Quiz 1
box is unchecked.
Exercise 7
Add 3 more legend entries to the rest of the check boxes. Remember to click the Add (not Edit) button.
When you are done, set the Students as the Horizontal Axis Labels.
There are times when it may be more useful to use Data Validation lists rather than the combo boxes we
used in this lab. In this case, you can always look up the index of the selected list item using the MATCH
function.
http://spreadsheetpage.com/index.php/tip/interactive_chart_with_no_macros/
Remember there are many different ways to create cool and useful charts in Excel. You are only limited
by how much you are willing to learn and how much effort you are willing to put in.