Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
26 views

Lab Activity 5

The document discusses creating dynamic drop-down lists and charts in Excel. It describes how to create a drop-down list for a column using data validation and named lists. It also explains how to use the OFFSET function to reference dynamic ranges in formulas and charts so they automatically update as new data is added. Exercises guide the user to create drop-down lists and name ranges to build a line chart that dynamically changes as temperature data is entered each month.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Lab Activity 5

The document discusses creating dynamic drop-down lists and charts in Excel. It describes how to create a drop-down list for a column using data validation and named lists. It also explains how to use the OFFSET function to reference dynamic ranges in formulas and charts so they automatically update as new data is added. Exercises guide the user to create drop-down lists and name ranges to build a line chart that dynamically changes as temperature data is entered each month.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Lab 5: Drop-Down Lists and Dynamic Charts

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.

Lab 5: Drop-Down Lists and Dynamic Charts


57
To create the drop-down list, first select the range in which the list will be used (see the illustration
below). Then under the Data tab, select Data Validation from the Data Tools group.

Lab 5: Drop-Down Lists and Dynamic Charts


58
Go to the Settings tab in the dialog box that pops up. In the Allow box, select List. We need to pick the
data source for our list. You can either enter = followed by the name of the list that was defined
previously, or you can use the arrow to the right of the Source field to select your list manually.

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.

Lab 5: Drop-Down Lists and Dynamic Charts


59
When you are done entering everything, press the OK button.

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.

Lab 5: Drop-Down Lists and Dynamic Charts


60
Exercise 2
Create a drop-down list (freshman, sophomore, etc.) for the Year column with an error message. The list
should not allow blank entries.

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:

OFFSET(reference, rows, cols, height, width)

where:

 Reference: is the address of a cell or a range of adjacent cells


 Rows: is the number of rows to move from the reference. A positive number means moving
down, and a negative number means moving up from the reference.
 Cols: is the number of columns to move from the reference. A positive number means moving
right, and a negative number means moving left from the reference.
 Height: is an optional positive value indicating the number of data rows to be returned by the
function.
 Width: is an optional positive value indicating the number of data columns to be returned by the
function.

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.

Lab 5: Drop-Down Lists and Dynamic Charts


61
The value returned is -6 since the function reads as follows: move one row down (first 1) from cell A2
and one column right (second 1) of cell A2, and return a single cell. A height and width of 1 (third and
fourth 1s, respectively) indicate it is a single cell that we are offsetting to. This is cell B3, which contains -
6, the returned value. When both the height and width are 1s, these arguments can be simply left out.
For instance, OFFSET(A2, 1, 1, 1, 1) is equivalent to OFFSET(A2, 1, 1)

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.

Lab 5: Drop-Down Lists and Dynamic Charts


62
Now what if we want this SUM value to be updated whenever we add a new month’s value? Of course
one way is modify the formula SUM(OFFSET(A1, 1, 1, 5, 1)) to include the newly added month. However,
this is cumbersome. We would like this to be done automatically and without changing the formula that
contains the OFFSET function. A combination of OFFSET and COUNTA can be very powerful.

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.

Lab 5: Drop-Down Lists and Dynamic Charts


63
Now try adding a new value to our table: Jun and 13.5.

The SUM(OFFSET(A1,1,1,COUNTA($B:$B)-1,1)) function automatically includes the June value (13.5) in


the sum since column B contains a new non-empty value now.

Lab 5: Drop-Down Lists and Dynamic Charts


64
Dynamic charts
In this section, we will take a look at how to make a chart that dynamically updates its values. Data is
dynamically added to charts by using the OFFSET function. Start by deleting the SUM formula that was
created previously. Remember how we named a range of cells in the drop-down sheet? This time we
will be naming formulas.

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

Lab 5: Drop-Down Lists and Dynamic Charts


65
Exercise 3
Create a Name (Temps) for the temperature column.

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.

Click on the Add button under Legend Entries.

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.

Lab 5: Drop-Down Lists and Dynamic Charts


66
Type in the reference to the Months formula and press the OK button.

Next, on the Select Data Source dialog box, press the OK button. Your chart should look like this:

Lab 5: Drop-Down Lists and Dynamic Charts


67
Try adding new data to the table and watch how the chart gets updated.

Lab 5: Drop-Down Lists and Dynamic Charts


68
Note that in the dynamic chart we created, because the average temperatures for some months are
negative and the x-axis crosses y-axis at the temperature of 0o, the x-axis appears in the middle of the
chart. If you want to move the position of the x-axis, open the Format Axis dialog by right-clicking on the
y-axis as shown below.

Lab 5: Drop-Down Lists and Dynamic Charts


69
In the Format Axis dialog box that appears, under “Horizontal axis crosses”, enter “Axis value” to be the
lowest temperature value along the y-axis, which is –10. Press the Close button when you are done.

Lab 5: Drop-Down Lists and Dynamic Charts


70
Now the chart will look as follows:

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.

Lab 5: Drop-Down Lists and Dynamic Charts


71

You might also like