CogSci 3 -- Excel
Due Saturday, November 7th; 11:59 PM 2009

Goals

This assignment will introduce you to some of the common functions of Microsoft Excel, using the Office Macintosh 2004 version.

  1. Learn some spreadsheet terms and concepts (e.g., "cell", "reference", etc.)
  2. You'll make up a simple spreadsheet with some sample student quiz scores.
  3. Import some data values and turn them into Excel columns
  4. Sort and join data
  5. Use the "Find What/Replace With" dialog
  6. Use some wild cards in "Find What/Replace With" dialogs
  7. Create some simple formulas to summarize the data
  8. Use the logical if function
  9. Create a simple chart
  10. Create a pivot table to summarize your data
  11. Use some text functions

We assume that you will be doing the assignment in the class Macintosh lab, or other campus Macintosh lab. This assignment is "turned in" by saving your work to your hw5 folder on your Macintosh File server.

Important Note:

Starting Excel

Locate Excel in the Applications Folder (i.e., Applications->Microsoft Office 2004-> Microsoft Excel) and start it.

Excel terms

We will try to cover these terms quickly during lecture. See the figure below where the active cell is B3 (with the heavy border). Both cell B3 and the formula bar contain the text "This is the formula bar".

Getting Help While Using Excel

The Help system in both Excel (and Word) is quite good! We suggest you make use of it if you get stuck.

Excel Help

Start up Firefox

You will need Firefox (or Safari) to copy some data from the assignment page. If you haven't already started Firefox, then start it up now, and navigate to the web page for this assignment.

Importing Data

Let's put some data into the spread sheet. Normally, you would type the data (numbers) in yourself. Or you might import information saved as text in a file, perhaps information from a database, using File->Open. Here we are going to copy and paste in the numbers and data.

When you copy and paste between applications, you usually want to "get back" exactly what you "put in". Excel and spreadsheets are a little different in this respect. You want to "put in" text and "get back" columns (and rows) of data. That is, you want Excel to recognize the data as being organized as a table in columns and rows.

When you paste data into a worksheet, Excel uses the TAB character (or csv format, a comma) as the column delimiter. A delimiter is a specially recognized character that is used to separate things, columns in this case. That is, in the text you paste, a TAB tells Excel when to start a new column; somewhat like a <td> in XHTML. The RETURN (end of line) character at the end of each line tells Excel to start a new row; sort of like a </tr> (or perhaps the <tr> that starts the next row).

The Data: Student Scores

Here is the first data table, quiz scores for a group of fictional students. The first column is the "student ID" number, followed by 4 columns of quiz scores.
A0011   15   17   15   15
A0021   10   13   16   19
A0024   13   19   14   13
A0036   20   19   20   20
A0032   19   16   18   18
A0002   15   17   13   15
A0041   20   19   19   16
A0031   17   17   18   19
A0012   20   20   19   20
A0033   11   19   19   18
A0020   19   12   18   14
A0022   18   19   17   17
A0005   12   17   16   14
A0008    8   15   10   16
A0030   13   18   17   14
A0027   16   20   19   19
A0029   18   19   20   19
A0018   17   18   12   20
A0037   18   19   16   20
A0023   19   13   14   15
A0019   18   17   17   20
A0009   16   18   14   12
A0007   13   15        18
A0035   16   20   19   19
A0038   16   15   19   19
A0034   19   16   19   19
A0003   17   18   18   19
A0010   14   17        15
A0013   15    6   17    8
A0006   19   20   19   19
A0004   15   18   20   17
A0028   19    0   20   20
A0026   13   19   18   19
A0025   19   13   17   18
A0016   10   19   13   19
A0015   15   13   18   14
A0017   11   13   15   11
A0014   17   17   12   12

A0001   13   15   14   11

Copy and Paste the Scores

Copy the data (including the IDs) from the Firefox page by Selecting it with the mouse, then Copying (CMD+C) it. Switch to Excel (click on the icon on the dock, or use CMD+Tab to cycle through the open applications if you can't see a part of your Excel worksheet to click on) Click in cell A1 of your empty worksheet, and paste the data (CMD+V).

It will look a little funny. That's because all the data has been pasted into the A column, not into 5 columns (A through E) as you would have hoped.

The problem is that when you copy text from Firefox (or even from a SSH window), there may be no TAB characters. Firefox (and SSH) convert the TABs to spaces when the text is printed on the screen. Thus, when you copy, there may be no TAB delimiters to tell Excel when to start the next column.

For this type of "paste" operation, Excel has a nifty feature called "Text to Columns" which is located in the Data menu. The "Text to Columns" wizard dialog takes you through a series of steps that allow you to describe (to Excel) the format of the data that you are importing.

Text to Columns

Make sure your data in the A column is still selected; if not, re-select it.
  1. Now select "Text to Columns..." in the Data Menu
  2. A dialog will open showing you the first line of the data, about like this:
  3. A0013    15     6    17     8
    
  4. The dialog lets you choose either delimited or fixed width to specify what text should go into which columns.
    1. "Delimited", of course, means there is a special character, like a comma or TAB, which specifies where to end one column and to start the next. There might be several of the same delimiter per row if you wanted to have more than just 2 columns.

    2. Fixed width, on the other hand, means that the same column in every row has the same number of characters in it. If a particular cell in that column has less than that number of characters, spaces (blank characters) are used as padding to make up the difference. Thus, the size for each column is a fixed number of characters. Different columns can have different widths, so long as every cell in a given column is the same width (including the padding) as every other cell.

  5. The table of scores was created and displayed in a fixed width font, so every thing lines up nicely. We'll have Excel treat it as a fixed width object. Select 'fixed width' and click Next.
  6. The next dialog of the wizard (called Step 2 of 3) lets you specify the spacings between the columns. Click between each pair of columns of data to create a column break. You can change the spacing by dragging the lines between the columns. Click Next.
  7. Step 3 of 3 in the dialog is about setting the data types. You can just click finish.
  8. Your data should be transformed into a 5 column table.
Your worksheet should now look about like:

Save As

Before you go any further, save a copy of your work so far. Open the File->SaveAs dialog. Change the name of your document to your account name (e.g., cg3fxx.xls). Save it in your hw5 folder on the file server-- i.e., in hw5 located in the cg3fxx folder in the "Class Resources". Create the hw5 folder, if one doesn't already exist.

Note: if you have trouble accessing the class server via the "Class Resources" folder, you should review the "turn in" document and use one of the alternative methods to turn your assignment in.

Note that in Office 2004, Excel has an option (in the SaveAs dialog) to add the .xls filename extension to your document name, to be compatible with the Windows operating system. You should make sure that box is checked.

Insert a New Row

In order to add headings to the columns, you first need to insert a new row to type them into.
  1. Select all of row 1 by clicking on the number 1 on the left edge of the worksheet..
  2. The whole row should be highlighted.
  3. Select Cells (or Rows)... from the Insert menu.
  4. The IDs and quiz scores should move down one row, and a new empty row should appear as row 1.
Creating a new row or column is always done this same way. Select a row or column by clicking on the row number to the left or column letter above. Then use Cells (or Rows/Columns) in the Insert Menu. The new row will appear above the selected row, or the new column will appear to the left of the selected column.

Column Headings
Typing in Data

To add data to the worksheet, simply click in the desired cell and type the number or text. End the typing by either clicking in another cell, typing RETURN, or typing TAB. Add the following headings to each column. Hint: use TAB to complete each entry and move the active cell to the right.
  1. In cell A1, put Student ID
  2. In cell B1, put Quiz 1
  3. In cell C1, put Quiz 2
  4. In cell D1, put Quiz 3
  5. In cell E1, put Quiz 4

The Student Names

The second table is a list of names taken from a TV cartoon show. The list was obtained with help from the compilation at http://www.snpp.com/guides/castlist.html. We've appended a "student ID" to each name.
Bart Simpson A0008
Lisa Simpson A0016
Montgomery Burns A0021
Cecil Terwilliger A0032
Selma Bouvier A0010
Beatrice Simmons A0026
Ned Flanders A0013
Nelsen Hunts A0031
Maude Flanders A0002
Edna Krabappel A0009
Jebidia Springfeld A0004
Otto Manns A0003
Cornelius Talmadge A0035
Clancy Wiggum A0005
Patty Bovier A0007
Kent Brocmann A0019
Herbert Powel A0030
Hans Molemen A0006
Martin Princess A0038
Janey Hagstreem A0028
Seymour Skinner A0018
Ralph Wiggum A0034
Todd Flanders A0025
Apu Nahasapeemapetilon A0015
Troy McClure A0020
Dewey Largoon A0023
Nick Rivera A0011
Krusty Clown A0001
Joseph Quimby A0022
Elizabeth Hoover A0029
Allison Taylor A0037
Barney Gumbel A0014
Waylend Smithers A0017
Silvia Winfield A0024
Rod Flanders A0036
Manjula Nahasapeemapetilon A0027
Langdon Alger A0041
Samantha Stanky A0033
Homer Simpson A0012
What you want now is to merge this information with the table (IDs and scores) you already have. In particular, you want to add a new column to your spreadsheet which has the students' names in it. And you'll want to join (match) those names in the new table with the corresponding scores in the original table by using the ID numbers.

Create New Columns

First, create 2 new columns to hold the student IDs and names by clicking in the letter "A" to select column "A", and then, Insert->Columns. This first column will hold the student names. With column A (still) selected, again select Insert->Columns, to hold the student IDs.

Copy and Paste the Names and IDs

Copy the names and student IDs from the table on the Firefox page. Paste the them into your spreadsheet, starting in cell A2 (not cell A1); row 1 is for the column headings.

Again, all the data has been put into one column, the A column. Observe how the information you pasted seems to extend into column B! If you look closely, however, you will see that there is no column divider line in those cells between column A and B now. (If you scroll below the table, the vertical border line between cell A and B will be visible again.) This is Excel trying to show as much information in a cell as possible by extending over blank cells. It is also the reason the information stops abruptly in column C where the cells are not empty.

Copy and Paste Again

Now, Copy and Paste Again into B2. The reason for this will be clear shortly, but you are going to remove all of the names from the first column and all of the IDs from the second. Read on and it will explain how to do this.

Text to Columns Again, But...

Recall that previously when you pasted data into the spreadsheet, you used "Text to Columns" to get the information properly placed in its respective columns. Let's try it again:
  1. Select the cells to be worked on (they are probably still selected due to your paste operation).
  2. Data->"Text to Columns"
  3. Then select "fixed width", and then click Next.
  4. Click Next again to see how to separate your data into columns. But there is no obvious way to drag the lines to separate all the columns cleanly.
  5. Don't click Finish.
  6. So the "fixed width" option is not going to work. But what about delimited? Click the "Back" button in the "Text to Columns" Wizard until you can select "Delimited" instead of "Fixed Width". Then click Next.
  7. There are "spaces" (hereafter as just spaces or SPACES without the quotes) which seem to separate the words. So select Space as a delimiter.
  8. Using space as a delimiter gives you 3 columns: first-name, last-name, and then ID. The first and last names will be separated! Darn.
  9. So, click Cancel in the "Text to Columns" dialog.
"Text to Columns" apparently won't work for you this time. We'll have to try something different.

If only ...

Imagine if the 2 "columns" were reversed, with the IDs first, and then the names following them with only a single space in between. For example:
...
A0002 Nick Rivera
A0015 Apu Nahasapeepetilon
A0004 Enda Krabappel
...
Here, it would be easy to specify how the "Text to Column" dialog should split that text into columns, because the first column, the IDs, are the same, fixed width.

But with your data, which has the names first and then the IDs, you will need different tool (wizard) to split it up into columns like you want.

Lets look carefully at some of the lines of data.

Bart Simpson A0008
Homer Simpson A0016
Montgomery Burns A0021
Notice that all the IDs start with a "A", and that the ID appears to be fixed length (but doesn't help us). If we could somehow delete that "A" and everything after it, that would leave just the names! Similarly, if we could delete the name and that space before the "A", it would leave just the IDs!

Using Replace

Excel has a "Find What/Replace With" feature (similar to MS Word). You are going to use the "Replace" dialog to first remove the names from one column of data. And then again to remove the IDs, leaving the names in the second column.

The typical use of the "Find What/Replace With" dialog replaces a fixed value or text string in your document another fixed value, like replacing "Simpson" with something like "Dolts". Let's try it as an exercise to see how it works.

  1. Your column A with the names and IDs should be still selected, if not reselect it
  2. Select Edit->Replace; you may have to select the down pointing arrows at the bottom of the Edit menu to get the Replace option to appear.
    1. In the "Find What:" part of the dialog, type in "simpson" (note: lowercase 's' at the beginning!). This is called the "target text" that the Replace command will look for.
    2. In the "Replace With:" box, type: "Dolt" but with out the '"' (quotes). This is the "new or substitution text" that will replace the target text.
  3. Click the "Replace All" button. The "Replace All" function will replace every instance of the target text in your selection in a single operation. On the other hand, the "Replace" button will do one substitution at a time under your control.
You should now have "Bart Dolt", and "Lisa Dolt" at the beginning of your list, and "Homer Dolt" at the end. Slick.

Note that you used all lower case in the search target, but found targets with capital letters. Excel must be using a case insensitive search.

Close the Replace dialog and select Edit->Undo (Replacement) to restore the Simpson names.

Let's try another exercise.

  1. Your column A with the names and IDs should be still selected, if not, select it by dragging through it or use good old Shift+Click
  2. Select Edit->Replace
    1. In the "Find What:" part of the dialog, type in "simpson" again as the target text.
    2. In the "Replace With:" box, type nothing. That is, make sure the "Replace With:" text box is empty.
  3. Click the "Replace All" button.
You should now have "Bart A0008", and "Lisa A0016" at the beginning of your list, and "Homer A0004" at the end. You erased their last names! The Replace dialog can be used to erase/delete either the names or IDs, if only we can specify them properly in the target text box. This should give you some ideas about how to get your names and IDs formatted into columns.

Close the Replace dialog and select Edit->Undo (Replacement) to restore the Simpson names.

Wild Cards

The column of text that we are dealing is complex; the ID numbers are different, and the names are very different from each other. We can't just do a simple replacement of something like Simpson -> Dolts to remove the names. We need to employ a wild card in the "Find What:" box in order to specify what target text to work with. A wild card is a special character that creates a search pattern that can match several different potential target strings of text. Excel uses the wild card "*" to mean "any number of characters" (including zero characters), when used in a "Find What:" dialog.

For example: suppose you had a list of words: art, ant, bat, cat, rat, brat, saint, smart, paint, plant, and tart. The pattern "*art" would match: art, smart, and tart. [Note: the fact that "*art" matches "art" is an example of where the "*" matched zero characters.] The pattern "s*" would match saint, and smart. And "*t" would match all the words, as does "t*"; why? Remember, the "*" can match 0 characters.

You should be able to use the "*" wild card in a Replace dialog to delete the student names, leaving only the ID.

  1. Make sure that IDs and Names are in the A column are still selected. If not, Shift+click is a very handy way to select a range (group of adjacent) of cells in Excel. Click in the first cell you want, then (perhaps scroll) and Shift+click in the last cell you want; all the cells in between will be selected as well.
  2. Edit->Replace
  3. In the "Find What:" box, type: *A0
    Again, the "*" is a wild card which matches any number of characters (including no characters). We are telling Excel to search for cells containing "A0". and those cells will match all the text from the left of the line, up to and including the 'A0' (though we discovered earlier that the search is case insensitive). Note that '0' refers to zero, not 'O'. The Excel "*" wild card will match as many blocks of text possible. So if the text has 2 (or more) "A0"s in it, the "*A0" would match the all the text from the left to the rightmost "A0".
  4. Make sure the "Replace With:" box is empty.
  5. Click Replace All. All the text found (i.e., the student names) are replaced with nothing; i.e., deleting them.
  6. Only the IDs (A0008) should remain.
But, whoops! It's not quite right. The "A0" that starts the ID got deleted too! (And Excel stripped the leading 0s off the numbers, because decimal numbers don't have leading 0s.)

Select Edit->Undo (Replacement). We'll have to modify your Replace so the "A" is not removed. Now:

  1. Use "*A0" as the target text, and "A0" as the substitution text. This is probably the best, as it explicitly defines the target should only match the text up to and including the "A0" part of the ID.
And then Replace again. This time only the IDs (A0008) should remain in column A. Now you are ready to create the second column with just the names.

A Wildcard to Delete the IDs, Leaving the Names

Now, to eliminate the IDs, an obvious thing to do is to use the Replace dialog and enter: "A*" in the "Find What:" box.

Use Replace again to remove the student IDs. as follows:

  1. Edit->Replace
  2. In the "Find What:" box, type: A*
  3. Make sure the Replace With: box is empty.
  4. Click Replace All
  5. The IDs (A0008) should disappear and only the names should remain.
Whoops! There is a problem again; too much was deleted from some of the entries. Remember, the "*" wild card will match multiple targets of text, if possible. This time the pattern is such that the "A" in "Lisa" and "Bart" match the target pattern too. Thus, the parts of the name to the right of the "A" are also removed.

Select Edit->Undo (Replacement) to put the IDs (and mangled names) back.

? versus *

Excel and other software that use wild cards typically will have a second wild card which matches any single character; Excel uses "?" for this purpose. The "?" can be used to create a target pattern that is a fixed length to help limit the scope of the match, or specify it more clearly.

For instance, "A???0" would match all the "words" starting with A, having exactly 3 characters followed by a '0' (zero); this pattern would match the ID "numbers", but probably none of the names, because there are no zero digits in the names.

By contrast, "A*0" will match the leftmost "A" in the names (if there are any), the rest of the name, and then the "A" in the ID and then up to the rightmost '0' in the IDs. For example, in the line "Lisa Simpson A0016", "A*0" would match the "a" in Lisa through the rightmost 0 in A0016. Actually, even our "A???0" has a problem with "Kent Brockman A0019", where it matches the "an" in Brockman: "an A0". In cases where there 2 or more possible fixed length patterns that match, the leftmost is the one used ("an A0", rather than the "A0019" we wanted).

On the other hand, the pattern "A0???" should match only the the IDs, since they (and no names) start with "A0" and have exactly 5 characters in them!

Now Delete the IDs

You need to modify your Replace so that only the IDs are removed, and not parts of the names.
  1. Make sure your column B names and IDs are still selected.
  2. Open the Replace dialog (Edit->Replace or ^H)
  3. Use " A0???" as the target text. Note we added a space to the left of the "A". Why? Your target text should have a space there too, and presumably you want to remove that space as well.
  4. The Replace With box should be empty, of course.
And then Replace again. This time only the names (e.g., Bart Simpson) should remain. Whew! At this point your worksheet should look about like the sample below

Note: we could also have used " A0*" (Space A Zero Star) instead of " A0???" as the target text. This will work too. Why?

Sort the IDs and Names

This is probably a good place to Save your work thus far.

Now that you have both the IDs and names, and IDs and scores, you can continue with your strategy of having Excel join them. First, you will sort the first 2 columns which contain the IDs and names.

  1. Select the both IDs and names in columns A and B using shift+click or by dragging through the cells. Important: do not select the empty cells in row 1! and make sure that only the first 2 columns with IDs and names are selected.
  2. Select Sort in the Data Menu.
  3. In the Sort dialog, set the "Sort by" to the column with the IDs (Column A), and check that "No header row" under "My list has" near the bottom of the dialog is checked.
  4. Click OK
  5. The IDs and names should move so the IDs start with A0001. The first row should be A0001 Krusty Clown.
  6. If you make a mistake, you may be able to undo it (CMD+Z) using the Edit Menu, and then try again.

Sort the IDs and Quiz Scores

Now sort the set of quiz scores along with the student IDs that came with them as follows.
  1. Select the IDs in column C and all the data through column G by dragging through it (or better, using shift+click). Important: make sure that you select all of the quiz scores as well as all of the IDs in column C. Do not select the IDs or names in the first 2 columns, and do not select the first row with the column headings (Student ID, Quiz 1, etc...), only the cells C2-G2 and then down until the end of the data.
  2. Select Sort in the Data Menu.
  3. In the Sort dialog, make sure the "Sort By" is the column with the IDs (Column C).
  4. Click OK
  5. The IDs and scores should move so the IDs start with A0001.

Verify the Sort Results

Do a quick check to make sure you haven't broken anything. The one student on the original Firefox list, A0013, should have quiz scores of 15, 6, 17, and 8. The another student on that list, A0004, should have scores of 15, 18, 20, and 17.

At this point, your worksheet should look something like (with more students, of course):

Quiz Totals

Now let's move on and start summarizing some of the quiz score data.

First, in column B1, type: Student Names. Then in column H1, type: Totals.

Now create a formula in H2 that adds the quiz scores for the first student. A formula is a calculation that uses numbers, cell references, and functions to derive a result. For instance, simply add (sum) the quiz scores in the cells D2 through G2 like: =D2+E2+F2+G2. (Formulas are always started with an "=".)

Or we could add those same cells using the Excel sum() function. (Functions are predetermined formulas that do their calculations using the values you specify called arguments.) The advantage of using the SUM() function is that we can specify which cells to add up as a range, which is easier to type than enumerating a large list of cells.

To enter the formula with the SUM() function:

  1. Click in cell H2
  2. Formulas always start with a "=", so
    Type: =
  3. Type: sum(
  4. Now you need to enter either a comma separated list like D2,E2,F2,G2 or the range of cells: D2:G2. Note there is a colon (:) between D2 and G2. There are several ways to enter a range of cells into a formula:
    1. Click in the first cell in the range (D2), and then shift+click in the end cell of the range (G2),
    2. Click in the first cell in the range (D2) and drag to the end cell of the range (G2),
    3. Click in the first cell in the range (D2), and then hold down the shift key and use the right arrow key repeatedly to select each cell in the range (G2),
    4. Or simply type in: D2:G2
  5. Now type the closing parenthesis: )
  6. Type: RETURN, or click the check box in the formula menu to complete the formula.
  7. Notice how the cell H2 no longer shows the formula, only the results (number) of the formula. Once you have completed a formula, the worksheet cell shows you the result, not the formula. If you need to change/edit the formula, click in the cell and then edit using the formula bar. You will also notice that Excel has capitalized SUM.

Fill Down

Copying a formula down a column or across a row is something that you do a lot in Excel. There is a special "Fill" function to copy a cell to multiple destination cells.

Copy the formula in H2 down through the column as follows:

  1. Select H2 down through as many cells as there are in the adjacent G column.
  2. In the Edit Menu, select Fill-> Down. All the cells that you selected should now have a number in them.
Click in your original H2 cell and look at the formula bar; in particular note the D2:G2 range in the SUM() function.

Now click in H5 and look at the formula bar; notice how the row references which were D2:G2 (row 2) have all been changed to D5:G5 (row 5) by Excel. The Fill Down operation has copied the formula and kept the cell references in the formula relative to the cell which contains the formula. I.e., the formula in each of the H cells sums the cells on its own row, not the original H2 row; e.g., cell H13 is the sum of D13:G13.

Relative and Absolute References

Excel normally uses relative references in formulas. That is, the formula is the sum of the 4 cells to the left, or, perhaps in another case, the cell above and the cell to the left. If you copy and paste the formula, or use Fill Down or Fill Right, the formula uses new cell references that are relative to the new cell that the formula is now in; i.e., the sum of the 4 cells to the left of that new cell.

The use of relative cell references in formulas is what let's you copy and paste formulas, and allows Fill Down and Fill Right work correctly. You can also specify absolute cell references when you wish a formula to refer to a single specific cell any where on the spreadsheet. Absolute references use a "$" to indicate their non-relative nature. For example: $B$3, or in a range: $D$2:$G:$22.

Find Average Scores

Now let's compute the average score for each quiz column and the totals column. As you should know, the average for a group of N numbers is the sum of the numbers (N1+N2+N3+...+NN) divided by N. Let's translate that into an Excel formula.

Suppose we wanted the average for the cells D2:D22 (you have more data than this, but for this example, let's assume). You now know that you can express the sum of the cells in D2:D22 as sum(D2:D22); then you just need to figure out what N is (how many cells there are in the range D2:D22).

The rows() Function

The rows() function returns the number of rows in its argument (which presumably is a range of cells). That number is just what we want for our "N" value.
  1. Locate the last cell used in the D (Quiz 1) column
  2. Click in the cell in the D column that is 2 cells below the last quiz score in the D column; i.e., so there is a blank cell between the last score and the cell you clicked in.
  3. Type in the formula: =rows(D2:DX)
    where X is the row number of the last quiz score in column D.
  4. When you complete the formula (with Enter or Tab), you should see the value X-2+1 in that cell.
  5. Click in the cell with the formula again, then use Edit->Fill->Right over to column H to copy/replicate your formula through column H, for the other 3 quizzes. There is actually another, perhaps handier way to Fill.
    1. Click in the original cell with the formula again
    2. Notice the small square in the bottom right corner of the cell border.
    3. When you move the cursor over that square, the shape changes to a '+', you can then drag to the right (or down) to do the Fill function.

The count() Function

Excel also has a count() function. As you might guess from it's name, it counts (tells you how many cells) the number of cells in its argument list. Using count(D2:DX) should also give you the "N" value.
  1. Click in the cell in the D column below the "rows" value/formula.
  2. Type: =count(D2:DX) (Again, X is the row number of the last quiz score in column D.
  3. When you complete the formula (with Enter or Tab), you should also see the value X-2+1 in that cell.
  4. Then use Edit->Fill->Right over to column H to copy, replicate your "count" formula through column H.

Missing Data

Notice the "count" values in column F (Quiz 3). The "count" function returns a value that is 2 less than the "rows" function. What is going on?

The problem is empty or blank cells. Blank cells have a special meaning in Excel. Some Excel functions (like count(), sum(), and average()) ignore blank cells; in other uses, a blank cell may cause an error. You also need to be careful sorting cells; blank cells are again treated differently (and may not sort like a zero value).

That's why you have a different value for the rows() and count() functions for Quiz 3; rows() really counted the number of rows, but count() counted only the non-blank cells.

Averages

Now lets turn our formulas for "N" into a real average. Click on the formula for "rows" in the D column, and then use the formula bar to change the formula into an average by adding the sum() of the cells and then dividing by it. I.e., change your =rows(D2:DX) to =sum(D2:DX)/rows(D2:DX). Then Fill->Right to copy across through column H.

The select the "count()" formula in column D and change it to also compute the average. Then use Fill Right to copy it through to column H. The averages in column F (Quiz 3) will be different, of course, because the 2 formulas are dividing by a different number.

Excel also has an average() function built into it. Let's use the built in function too, as a comparison.

  1. Click in the cell in the D column that's below the "count()" average.
  2. You can just type in the formula: =average(D2:DX). Or you can Insert->Function.
  3. If you don't see Average as one of the choices, try typing "average" in the "Search for" box at the top of the dialog; that will produce a list of functions that compute an average. Scroll until you find the Average() function, then double click on it.
  4. A dialog box will appear looking something like this:
  5. The dialog is a template the shows you what function arguments are required (and in what order). Type in your range: D2:X in the box called "Number1" to the function.
  6. Click OK to complete the formula. Notice that you don't need to type an = when you insert a function as the first thing in a cell.
Again, use Fill Right to copy the Average() formula through column H.

Number Formats

The averages have lots of digits to the right of the decimal point ("."). Numbers can be displayed in a variety of formats, including as dates, percentages, and currency (money). The different formats include options like how many decimal digits (to the right of the ".") are displayed, whether to use $ signs (for currency), how to display negative numbers, dates, etc.

Let's only show 2 digits to the right of the decimal place.

  1. Select the 3 rows with your Average()s in them.
  2. Select Cells in the Format Menu.
  3. Select the Number tab.
  4. Under "Category", select the second choice (Number), and you can specify how many decimal places to display (2).
  5. Click OK
Important: changing the number format does not change the value in the cell! It only changes the way the value is displayed/printed. For example, you haven't changed the 15.666667 to 15.67; you haven't lost any precision (data/information).

Standard Deviation

Another statistical function that is often used in computing grades is the standard deviation. The Excel name for this function is: stdev.
  1. In the "D" column, in the cell below the last average, enter a formula that computes the stdev for the quiz scores in column D (but not the Average). You can either type in the formula (don't forget to start with an '='), or use the Insert->Function dialog.
  2. Again, use "Fill Right" to copy the formula in to cells E through H.
  3. Use the Format menu to change the format for "stdev" row to show only 2 decimal digits (0.00) like you did with the averages.

Label the Averages and Stdev rows as follows:

  1. In column B, to the left of your "rows()" average, type "Average - rows".
  2. In column B, to the left of your "count()" average, type "Average - count".
  3. In column B, to the left of your Average(), type "Average - built in".
  4. In column B, to the left of your first stdev(), put the word: "Stdev".

The bottom part of your spreadsheet should look something like this:

Compute Pass/NoPass Grades

Some of the students in our class are taking it Pass/No Pass. There were 4 quizzes which each had 20 points maximum; so there were 4 * 20 = 80 points total. In order to receive a Pass grade, the students need to have 70% of the total points or more.

We would like to create a formula that looks to see if a student has more that 70% of the 80 (70% * 80) points. And if she does, assigns her a "P" (pass) grade, otherwise assigns a "NP" (no pass) grade. Here's how to do it:

  1. First, select cell I1 (capital "i", one), and label it: P/NP.
  2. Now in cell I2, enter:
  3. =if(H2>=80*70%, "P", "NP")
  4. Click the check box in the formula bar or type RETURN to finish the formula.
  5. Note: you must use the quote marks (") so the Excel knows you are referring to text to be printed rather than column P or NP. This is called quoting, where a special character (a (") in this case) is used to give or take away the special interpretation of the word or symbol following. Here the quotes are used to tell Excel that we are talking about just the letters "P" and "NP" rather than the names of columns or defined names.
  6. Select I2 and then Fill Down.
  7. You should now have a series of "P"s and a few "NP"s in column I.
You have just used the logical if function. The if function is one that you create, and specify how it should work. if takes 3 arguments separated by commas (,). The template looks like:
	if(test_argument , true_consequent , false_consequent)
The value or result of the function is either the value of the true_consequent or the false_consequent, depending on the value of the test_argument. That is, Excel computes the results of the test_argument, if the answer is TRUE, then the result of the if() is the true_consequent, "P" in our example. If the result of the test is FALSE, then the result of the if is the false_consequent, "NP".

In our if(), the value/result was text ("P" or "NP"). It could just as well have been a number, the value in a cell, or a more complicated formula involving calculations and formulas.

Letter Grades

Let's create a new formula to compute a letter grade in cell J2.
  1. Copy the formula in cell I2 into cell J2.
  2. Note that instead of referencing cell H2, the formula in J2 references cell I2. Again, that's because when you copy and paste formulas in Excel, the same relative cell relationships are kept.
Modify the formula in J2 so that it looks like the one below:
=if(H2>=80*70%, "C", "F")
This new formula says that if the total in H2 is greater than 70% then the result is a "C", otherwise it's an "F". This new formula tells us when a student has a "C" or above, or an "F". However, it would be nice to find out about "B"s and "A"s too. The cutoff between "B"s and "C"s is 80% (80*80%) in our case here. The "if" function format for that is:
if(H2>=80*80%, "B", "C")
You can nest or embed logical if functions by having a second if as either (or both of) the true consequent or false consequent. Replace the "C" (true consequent) argument in your original formula in J2 with this whole if. When you are done, you will have an embeddedif formula (an if inside an if).

Use "Fill Down" to a replicate your new formula into J2 through the end of the data. You should see some "C"s (e.g., Maude Flanders), some "B"s (e.g., Otto Mans), and a few "F"s (e.g., Krusty Clown). You're not quite done yet, though. Students above 90% (80*90%) should get an "A".

Modify cell J2 again. Replace the "B" with yet another (embedded) if that results in an "A" if H2 is greater than or equal to 80*90%, otherwise a "B". (You will need to figure out what this new if formula is.) Your final formula with have 3 if's in it.

Use "Fill Down" to a copy your new formula into the J column. You should see some of the "B"s change into "A"s; for instance, Otto Mans.

Finally, label column J (J1), "Grades".

Define a Constant

Excel lets you name both cells and constants to help you recall and understand what is going on in your calculations. Also, you can change your calculations by simply changing the value of the constant. Instead of having to locate every "80" (the maximum number of points) in your spreadsheet, you merely have to change the value associated with a constant. Let's define the constant MaxScore.

Now each place you use the number 80 and that 80 means the maximum quiz score value, you can use the name MaxScore. Test it out by replacing the 80 in cell I2 with MaxScore.

In a similar way, update the 3 if() tests in the formula in J2 to use MaxScore. Then use Fill Down to copy the new formulas from I2 down the I column and from J2 down the J column.

Delete a Column

We no longer need the redundant ID columns. Let's delete column A.
  1. Click in the A to select all of column A.
  2. Select Delete in the Edit Menu
  3. Notice that the all the columns have been renamed (slid to the left) and the formulas in columns G and H continue to work correctly!
At this point, your worksheet should look about like:

Save your work.

Copy Data to a New Worksheet

Now let's create a simple chart of the course percentages for the students. First, copy the total scores to a new worksheet, then sort the scores, create a chart, and finally, put a title on the chart.
  1. Select the total scores in in the G column, but not the "Totals" heading.
  2. Copy
  3. Select Sheet 2 at the bottom of the workbook.
  4. Select cell A1 in the new worksheet.
  5. Paste. You should see a column of "#REF!" What happened?
  6. Recall that column G on your original worksheet contained a formula that sum()ed the cells to the left of it. When you paste into column A, there are no cells to the left of column A to reference, so the formula can no longer work. You could paste further to the right, and the formula would be reasonable, except, of course, that there is no data in this spreadsheet for the formula to work on. If you think about it, what you really want is the values in the Totals column, not the formulas.
  7. Select Undo Paste in the Edit menu to clear column A on your new worksheet. If you can't "undo" simply delete the column that you pasted.
  8. Select cell A1 on your new worksheet again.
  9. In the Edit menu, select "Paste Special..."
  10. A new "Paste Special" dialog will appear that lets you select just what attributes of a cell you want to copy.
  11. Click on the Values button, then click OK.
  12. The values should now appear in column A.

Note: In Excel, in some cases, a little clipboard that appears when you can paste something. If it does appear you can select "Values only" there, rather than having to go to the Edit menu.

Sort and Create Percentage Formula

Use Sort in the Data menu, to sort the values in A column in descending order.

To convert a number into a percentage, you take the number (the cell in the A column) and divide it by the maximum value (MaxScore) and then multiply by 100. So select cell B1, and create the following formula:

=A1/MaxScore*100
which will turn the score in A1 into a percentage. Use Fill Down to replicate the formula in B1 down into cells in the B column.

Create the Chart

  1. The formula values in the B column should still be selected. If not, reselect them.
  2. Select Chart in the Insert Menu.
  3. Select a chart type, in the dialog that appears.  For this assignment, the default "Column" chart is fine.
  4. Click Next and a preview of the chart should appear.  You can change the Data Range for the chart in this dialog, but they should already be right.

Add a Title and Grid Lines

  1. Click Next to get the Chart Options.
  2. Select the "Titles" tab and in the Chart Title dialog, type in: "Course Final Percentages".
  3. Select the "Gridlines..." tab.
  4. Select "Major Gridlines" for the Y Axis.

Remove the Legend

  1. Select the Legend tab and uncheck the "Show legend" box.
  2. Click Next and place the chart as a new object in sheet 2.
  3. Click Finish.

Adding Color

  1. Click on the chart to select it.
  2. Click on one of the data bars to select it.
  3. Right-click on the data bar, and choose "Format Data Point"
  4. In the "Format Data Point" dialog box, choose the "Fill" option (on the left)
  5. At the bottom of the right side, click "Vary colors by point"
  6. You should now have a colorful chart.

Copy the Chart to Sheet1

  1. Click on the chart to select it
  2. Copy
  3. Select the Sheet1 tab at the lower left of Excel window
  4. Paste
Your worksheet should look about like:

Summarizing Data:
A Pivot Table

You summarized some of your quiz data by totaling scores, and by finding the average score for a particular quiz. You've done another kind of data summary using a chart to look at the sorted "total" values.

Excel has some built in summary capabilities as well. One of these is the pivot table that lets you count, average, or find the minimum or maximum of values.

We're going to have you create a simple pivot table count of the letter grades, and then create a pie chart from that. This will show you how many students got an 'A', 'B', etc.

  1. Select the column of letter grades (not P/NP ones), including the "Grades" heading from Sheet1 and copy
  2. Now select sheet 3 at the bottom of the Excel window to open a new, blank sheet
  3. Now paste in column A -- don't forget to Edit->Paste Special just the values, like you did before
Now it's just a matter of following the Pivot table wizard to create a summary of the grades.
  1. If your column of grades, including the "Grades" heading, on sheet 3 is not still selected, reselect it.
  2. Then start the wizard by selecting "PivotTable Report" in the Data menu
  3. Step 1 asks the type of data, which is a Microsoft Excel list, and which you have selected already
  4. Step 2 asks the range of data to use, which again you have already selected
  5. Step 3 asks "Where do you want to put the Pivot Table Report"? Click "Existing Worksheet", and then type: C2 into the text box below "Existing Worksheet".

  6. Still on the Step 3 dialog, click the "Layout" button which will bring up the dialog below.

  7. We want to summarize by grade type ("A", "B", etc). To do that click on the "Grades" button on the right hand side and drag it on top of the word "Row" in the table in the middle of the dialog
  8. And the summary we want is a count of the number of each grade. This you get by clicking on the "Grades" button again, and dragging it on top of the word "Data". Excel will change "Grades" to "Count of Grades", which is just what we want. Click OK.
  9. You should now be back on Step 3, and can click finish.
You should now see a small, new table in cell C2 with column heads, "Count of Grades, "Grades, and "Total". The Row labels will be "A", "B", "C", and "F". There will probably also be a couple of dialogs or toolbars that are used to work with the pivot table. If you don't see the Row labels ("A", "B", "C", "F"), you may have to click (or double-click) the word Grades in the PivotTable Field List.

the pivottable

A Pie Chart

Finally, let's further summarize the Pivot table by creating a Pie chart.
  1. Select the 4 "data" rows of your pivot table (rows "A" through "F") including both the letter and value to the right
  2. Select Insert->Chart.
  3. Then select "Pie" from the list of types. The default pie chart (the one Excel picks) should be fine, so click Finish
  4. Click on the chart itself again.
  5. On the "Formatting Palate", select "Other Options" (under Chart Options), and in Labels, select "Percentage".
You should now have a simple pie chart with percentages for each piece of the pie.

Pie Chart

Save your work at this point.

Rename the Sheets

  1. Select Sheet1 in your Workbook
  2. Use Format->Sheet->Rename and change the name of the sheet (tab at the bottom) to your class account code followed by Data (e.g., cg3fxx Data)
  3. Select Sheet2; Use Format->Sheet->Rename and call it Totals Chart
  4. Select Sheet3 Use Format->Sheet->Rename and call it Pivot Table
  5. Select the Sheet with your pivot table chart (probably called Chart1) Use Format->Sheet->Rename and call it Pivot Chart
Save your workbook using Save in the File menu.

Before you log out, verify that your work is indeed saved on the file server (i.e., in the Class Resources folder).

Extra Credit

For extra credit, you can do one or both of the following. (Hint: you can use Help in MS Excel to get some information about "Conditional formatting" and/or "text formulas".)

  1. Apply "Conditional Formatting" (in the Format menu) to the list of names on your first worksheet. The formatting should turn the background color of the cell (with the name on it) to red, if the student is going to get an 'F', and to green if the student is going to get an 'A'. There are a couple of ways to do this; pick the one that makes sense to you.
  2. Create a new column to right of the list of names. Create a formula using text formulas to take the "Firstname Lastname" in the cell to the left and change it to "Lastname, Firstname". Important: to get credit we want to see a formula in that column, not just the names reversed.

Save this in your hw5 folder too. The name will depend on which (or both) you attempted.


Portions ©opyright 1995-2005 Mark R. Wallen
Revised October 29, 2006 Mary ET Boyle
Revised for Macintosh, September, 2007 Mark Wallen