Lab Activity 5
Lab Activity 5
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:
We can choose whether we want to restrict the user’s entries to the list, displaying an error message on
any other entry. To do this, go to the Error Alert tab. Excel lets you pick the style of the error message,
as well as the message title and body.
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
error message. For instance, if you type =SUM(OFFSET(A1, 1, 1, 5, 1)) in an empty cell, you will get an
error message.
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
range is COUNTA($B:$B) – 1, which is one less the number of non-empty cells in column B. Remember
that the column title (Average Temperature (0C)) is a non-empty value, but it should not contribute to
the number of values we are trying to sum up. Hence, COUNTA($B:$B) – 1 evaluates to 6 – 1, which is 5.
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
created in, followed by an exclamation mark. Otherwise, Excel will not know where to find this name.
When you are done, press the OK button.
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
added.