cogs 3 -- excel - pages.ucsd.edupages.ucsd.edu/~mboyle/cogs3/assignments/04-assignment-excel.pdf ·...

20
Cogs 3 -- Excel Goals This assignment will introduce you to some of the common functions of Microsoft Excel, using the Microsoft Office. You are welcome to use a different version for Windows or Macintosh. The images in this assignment are from different versions of Excel. 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 This assignment may be done on a Mac or Windows system. This assignment is "turned in" by saving your work to your ExcelAssignment directory on the class server. Please also upload all your Excel files to TritonEd under the ExcelAssignment location. Note: Please do NOT place it in your public_html directory (you will recieve 50% deduction if it is there.) Important Note: We have added more student data to the assignment. All of the figures should be taken as examples rather than an exact copy of what your spreadsheet should look like. Your spreadsheet may also look slightly different because of an updated version of Excel. Starting Excel: Excel terms We will try to cover these terms quickly during lecture. Excel documents are called worksheets, Multiple worksheets are contained in a workbook. The worksheet is a grid of rows identified by their number and columns identified by letters (A-Z), or pairs of letters (AA-AZ, BA-BZ, etc). The intersection of a row and column creates a cell. One cell is the active cell, which is the one you have clicked on and has a heavy border, though you may not see it on the screen if you scrolled. Cells are named for the column and row they are in, column name first; e.g., A3, E43, BB10, etc. That name is called the cell reference. Immediately above the row containing the column letter names is the formula bar. The left portion of the formula bar (above column A) is the name box, which has the cell reference of the active cell. (It can also be used to select a new active cell by typing a new cell reference into it.) 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.

Upload: buingoc

Post on 04-Nov-2018

234 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

Cogs 3 -- ExcelGoals

This assignment will introduce you to some of the common functions of Microsoft Excel, using the Microsoft Office. You are welcome to use a different version for Windows or Macintosh. The images in this assignment are from different versions of Excel.

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 columns4. Sort and join data5. Use the "Find What/Replace With" dialog6. Use some wild cards in "Find What/Replace With" dialogs7. Create some simple formulas to summarize the data8. Use the logical if function9. Create a simple chart

10. Create a pivot table to summarize your data11. Use some text functions

This assignment may be done on a Mac or Windows system. This assignment is "turned in" by saving your work to your ExcelAssignment directory on the class server. Please also upload all your Excel files to TritonEd under the ExcelAssignment location.Note: Please do NOT place it in your public_html directory (you will recieve 50% deduction if it is there.)

Important Note:

We have added more student data to the assignment. All of the figures should be taken as examples rather than an exact copy of what your spreadsheet should look like. Your spreadsheet may also look slightly different because of an updated version of Excel.

Starting Excel: Excel terms

We will try to cover these terms quickly during lecture.

Excel documents are called worksheets,Multiple worksheets are contained in a workbook.The worksheet is a grid of rows identified by their number and columns identified by letters (A-Z), or pairs of letters (AA-AZ, BA-BZ,etc).The intersection of a row and column creates a cell.One cell is the active cell, which is the one you have clicked on and has a heavy border, though you may not see it on the screen if youscrolled.Cells are named for the column and row they are in, column name first; e.g., A3, E43, BB10, etc. That name is called the cell reference.Immediately above the row containing the column letter names is the formula bar.The left portion of the formula bar (above column A) is the name box, which has the cell reference of the active cell. (It can also be usedto select a new active cell by typing a new cell reference into it.)

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 formulabar".

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.

Page 2: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

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.

Page 3: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

When you copy and paste between applications, you usually want to "get back" exactly what you "put in." Excel and spreadsheets are a littledifferent 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 asbeing 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 aspecially 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 starta 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 ofquiz scores.

A0011 15 17 15 15A0021 10 13 16 19A0024 13 19 14 13A0036 20 19 20 20A0032 19 16 18 18A0002 15 17 13 15A0041 20 19 19 16A0031 17 17 18 19A0012 20 20 19 20A0033 11 19 19 18A0020 19 12 18 14A0022 18 19 17 17A0005 12 17 16 14A0008 8 15 10 16A0030 13 18 17 14A0027 16 20 19 19A0029 18 19 20 19A0018 17 18 12 20A0037 18 19 16 20A0023 19 13 14 15A0019 18 17 17 20A0009 16 18 14 12A0007 13 15 18A0035 16 20 19 19A0038 16 15 19 19A0034 19 16 19 19A0003 17 18 18 19A0010 14 17 15A0013 15 6 17 8A0006 19 20 19 19A0004 15 18 20 17A0028 19 0 20 20A0026 13 19 18 19A0025 19 13 17 18A0016 10 19 13 19A0015 15 13 18 14A0017 11 13 15 11A0014 17 17 12 12

A0001 13 15 14 11

Copy and Paste the Scores

Copy the data (including the IDs) from the Pdf page by Selecting it with the mouse, then Copying (command key ⌘ + C) it. Switch to Excel (click on the icon on the dock, or use command key ⌘ + TAB to cycle through the open applications if you cannot see a part of your Excel worksheet to click on). Click in cell A1 of your empty worksheet, and paste the data (command key ⌘ + 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 Chrome (or even from a SSH window), there may be no TAB characters. The TABs have been converted 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

Page 4: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

2. A dialog will open showing you some of the data, about like this:

A0013 15 6 17 8

3. The dialog lets you choose either delimited or fixed width to specify what text should go into which columns.a. "Delimited" 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.

b. "Fixed width," on the other hand, means that the same column in every row has the same number of characters in it. If a particularcell 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 ina given column is the same width (including the padding) as every other cell.

4. The table of scores was created and displayed in a fixed width font, so everything lines up nicely. We'll have Excel treat it as a fixedwidth object. Select 'fixed width' and click Next.

5. The next dialog of the wizard (called Step 2 of 3) lets you specify the spacings between the columns. You can click between each pair ofcolumns of data to create a column break. You can also change the spacing by dragging the lines between the columns.

6. 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. If the font in column A appears to be too small, you may increase the font size.

Your worksheet should now look like:

Save As

Before you go any further, save a copy of your work so far. Open the File->Save As dialog. Change the name of your document to your account name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment directory on the file server.

Note: You should save files to your computer instead of OneDrive, SharePoint, or iCloud Drive. Recommended location: Documents > Cogs3 > ExcelAssignment folder.

Note: You should access the class server using a program like CyberDuck to transfer your files.

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. From the Insert menu, select Cells (or Rows).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 letterabove. Then use Cells (or Rows/Columns) from the Insert menu. The new row will appear above the selected row, or the new column willappear to the left of the selected column.

Column Headings: Typing in Data

Page 5: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

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 tothe right.

1. In cell A1, put Student ID2. In cell B1, put Quiz 13. In cell C1, put Quiz 24. In cell D1, put Quiz 35. 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 athttp://www.snpp.com/guides/castlist.html. We have appended a "student ID" to each name.

Bart Simpson A0008Lisa Simpson A0016Montgomery Burns A0021Cecil Terwilliger A0032Selma Bouvier A0010Beatrice Simmons A0026Ned Flanders A0013Nelsen Hunts A0031Maude Flanders A0002Edna Krabappel A0009Jebi Springfeld A0004Otto Manns A0003Cornelius Talmadge A0035Clancy Wiggum A0005Patty Bouvier A0007Kent Brocmann A0019Herbert Powel A0030Hans Molemen A0006Martin Princess A0038Janey Hagstreem A0028Seymour Skiner A0018Ralph Wiggum A0034Todd Flanders A0025Apu Nahasapeemapetilon A0015Troy McClure A0020Dewey Largoon A0023Nick Rivera A0011Krusty Clown A0001Joseph Quimbey A0022Elizabeth Hoover A0029Alison Taylor A0037Barney Gumbell A0014Waylend Smithers A0017Silvia Winfield A0024Rod Flanders A0036Manjulla Nahasapeemapetilon A0027Langdon Alger A0041Samantha Stanky A0033Homer 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 columnto your spreadsheet which has the students' names in it. And you'll want to join (match) those names in the new table with the correspondingscores 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 Pdf file. Paste the them into your spreadsheet, starting in cell A2 (not cell A1); row1 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 youlook 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 thetable, 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 possibleby 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

Page 6: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

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 columnand 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 itsrespective 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 check only 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 RiveraA0015 Apu NahasapeepetilonA0004 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 a different tool (wizard) to split it up into columns like you want.

Let's look carefully at some of the lines of data.

Bart Simpson A0008Homer Simpson A0016Montgomery Burns A0021

Notice that all the IDs start with a "A" and that the ID appears to be fixed length (but does not 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. Select column A with the names and IDs.2. Select Edit-> Find-> Replace...

a. In the "Find what:" part of the dialog, type in "simpson" (note: lowercase 's' at the beginning!). This is called the "target text" thatthe Replace command will look for.

b. In the "Replace with:" box, type: "Dolt" but with out the '"' (quotes). This is the "new or substitution text" that will replace the targettext.

3. Click the "Replace All" button. The "Replace All" function will replace every instance of the target text in your selection in a singleoperation. 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.

Page 7: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

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 Replace 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

a. In the "Find what:" part of the dialog, type in "simpson" again as the target text.b. 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 A0012" at the end. You erased their lastnames! 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. Thisshould give you some ideas about how to get your names and IDs formatted into columns.

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

If you are unable to Edit->Undo Replace, manually type in the last name "Simpson" between Bart, Lisa, and Homer's first names and ID. (i.e.Homer Simpson A0012)

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 justdo a simple replacement of something like Simpson -> Dolts to remove the names. We need to employ a wild card in the "Find what:" box inorder to specify what target text to work with. A wild card is a special character that creates a search pattern that can match several differentpotential 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 matchsaint, 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 the IDs and Names are in column A are still selected. If not, SHIFT + CLICK is a very handy way to select a range (groupof 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 thecells in between will be selected as well.

2. Edit-> Find-> Replace3. 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 cellscontaining "A0". and those cells will match all the text from the left of the line, up to and including the 'A0' (though we discovered earlierthat 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, becausedecimal numbers don't have leading 0s.)

Select Edit->Undo Replace. 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 thetext up to and including the "A0" part of the ID.

And then Replace All again. This time only the IDs (A0008) should remain in column A. Now you are ready to create the second column withjust the names.

A Wildcard to Delete the IDs, Leaving the Names

Now, to eliminate the IDs in column B, 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:

Page 8: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

1. Edit-> Find-> Replace2. 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 oftext, 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 theright of the "A" are also removed.

Select Edit->Undo Replace 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 "?" forthis 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 matchthe 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 therightmost '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 there2 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 inthem!

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)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 All 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:

Page 9: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

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 willsort the first 2 columns which contain the IDs and names.

1. Select both the IDs and names in columns A and B using SHIFT + CLICK or by dragging through the cells. Important: Do NOT selectthe empty cells in row 1! 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 under "My list has" near the bottom of the dialog, make

sure "No header row" is selected.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 (command key ⌘ + Z) using the Edit Menu and 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: makesure 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, anddo 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 thedata.

2. Select Sort in the Data Menu.

Page 10: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

3. In the Sort dialog, make sure the "Sort by" is the column with the Student 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 have not broken anything. The one student on the original Chrome list, A0013, should have quiz scores of15, 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:

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, andfunctions to derive a result. For instance, simply add (sum) the quiz scores in the cells D2 through G2 like: =D2+E2+F2+G2. (Formulas arealways started with an "=".)

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

To enter the formula with the SUM() function:

1. Click in cell H22. Formulas always start with a "=", so type: =

Page 11: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

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:a. Click in the first cell in the range (D2), and then SHIFT + CLICK in the end cell of the range (G2),b. Click in the first cell in the range (D2) and drag to the end cell of the range (G2),c. 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),d. Or simply type in: D2:G2

5. Now type the closing parenthesis: )6. Press the RETURN key 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 theformula 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 tomultiple 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 lets 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) column2. 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.

Page 12: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

a. Click in the original cell with the formula againb. Notice the small square in the bottom right corner of the cell border.c. 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 its 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 let's 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, Edit->Fill->Right to copy across through column H.

Then 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:

Page 13: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

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 boxcalled "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. Under "Category," Select the Number tab.4. Specify 2 decimal places.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. Forexample, 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 theAverage). 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".

Page 14: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

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

Compute Pass/No Pass Grades

Some students were taking the class as Pass/No Pass. There were 4 quizzes which each had 20 points maximum; so there were 4 * 20 = 80 pointstotal. In order to receive a grade of Pass, the students needed 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:

=if(H2>=80*70%, "P", "NP")

3. Press the RETURN key to complete the formula.Note: You must use the quotation marks (") so Excel knows you are referring to text to be printed rather than column P or NP. This iscalled quoting, where a special character (a (") in this case) is used to give or take away the special interpretation of the word or symbolfollowing. Here the quotes are used to tell Excel that we are talking about just the letters "P" and "NP" rather than the names of columnsor defined names.

4. Select I2 and then Fill Down.5. 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 argumentsseparated 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 thetest_argument. That is, Excel computes the results of the test_argument, if the answer is TRUE, then the result of the if() is thetrue_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 formulainvolving 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 embedded if formula

Page 15: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

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

Use the Insert->Name->Define dialog to define a name of "MaxScore" which has the value of 80. Note: there is no space between the words "MaxScore"; spaces are not allowed in Excel names.To enter the value in the "Select the range of cells" box (or "Refers To" box), type: =80Then click the OK button.

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 byreplacing the 80 in cell I2 with MaxScore.

Note the value of the cell I2.Now click on cell I2 to open it in the formula bar.Replace the 80 with MaxScore.Press the RETURN key to complete the formula.Verify the value is the same as in the first step--unchanged.

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 Icolumn 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 Menu3. 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

Page 16: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

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. Copy3. Select Sheet2 at the bottom of the workbook. If Sheet2 is missing, click on the "+" symbol at the bottom to add a second sheet.4. Select cell A1 in the new worksheet.5. Paste. You should see a column of "#REF!" What happened?

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 columnA, 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 theformula 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.

6. 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 youpasted.

7. Select cell A1 on your new worksheet again.8. In the Edit menu, select "Paste Special..."9. A new "Paste Special" dialog will appear that lets you select just what attributes of a cell you want to copy.

10. Click on the Values button, then click OK.11. 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 column A in descending order (largest to smallest).

To convert a number into a percentage, you take the number (the cell in column A) 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 column B should still be selected. If not, reselect them.2. Select Chart in the Insert Menu.3. Select a chart type. For this assignment, choose the default (first) "Column" chart.4. A chart (or a chart preview) should appear.

Add a Title and Grid Lines

1. To customize the chart, select the Format tab (or under the View menu, select Formatting Palette). Make sure your chart is selected.2. Select Chart Title and add or change the title in the chart by typing the new title into the box (or under the "Chart Options" header in

the Formatting Palette, type: "Course Final Percentages" in the textbox labeled "Click here to add title.").3. Select the Chart Design tab -> Add Chart Element -> Gridlines, and make sure "Primary major Horizontal" is checked.

Remove the Legend (if present)

1. With the chart still selected, select Add Chart Element -> Legend and make sure "None" is checked.

Adding Color

1. Again, make sure the chart is still selected.2. Click on one of the data bars.3. At the top menus, go to Format-> Chart Data Series and click the paint bucket icon from the right window.4. Under the Fill option, select "Vary colors by point."5. Click OK.6. You should now have a colorful chart.

Page 17: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

Copy the Chart to Sheet1

1. Click on the chart in Sheet2 to select it.2. Copy.3. Select the Sheet1 tab at the lower left of Excel window.4. Paste.

Your sheet1 should look like this:

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 ofdata 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 ormaximum 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 howmany 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 Sheet3 at the bottom of the Excel window or the "+" symbol 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 options to create a summary of the grades.

1. If your column of grades, including the "Grades" heading, on Sheet3 is not still selected, reselect it.2. Then create the PivotTable by selecting "Summarize with PivotTable" in the Data menu.3. Step 1 asks for the range of data to use, which you have already selected.4. Step 2 asks where to place the PivotTable. Select "Existing sheet", and then type: C2 into the text box below.

Page 18: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

5. We want to summarize by grade. To do that, drag "Grades" from Field Name into the Rows box.

6. The summary we want is a count of the number of each grade. This is what should automatically appear inside the Values box, but if itdoesn't, click inside the Values box and select Summarize by -> Count.7. Exit the PivotTable builder.

You should now see a small, new table in cell C2 displaying the grades, Count of Grades, and a Grand Total. Your table should look something like this (but may appear different for different versions).

Page 19: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

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 first one displayed on the left in Excel should be fine, so click on the

first pie chart style.4. Make sure the pie chart is selected. If not, click on the chart itself.5. Select "Quick Layout" from the top of the worksheet. Choose the option that shows percentages inside the pie pieces and places the

legend to the right of the pie chart.6. Change the chart title to "Letter grade percentages."

You should now have a simple pie chart with percentages for each piece of the pie.

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 ID followed by Data (i.e., cg3xzz

Data).3. Select Sheet2. Use Format->Sheet->Rename and name it Totals Chart.4. Select Sheet3. Use Format->Sheet->Rename and name it Pivot Table.

You should have a total of 3 sheets.

Save your workbook using Save under the File menu.

Save your workbook to your computer and verify that your work is also saved on the file server (i.e., use CyberDuck or FileZilla). Upload your file to TritonEd for the ExcelAssignment assignment.

Extra Credit

Page 20: Cogs 3 -- Excel - pages.ucsd.edupages.ucsd.edu/~mboyle/COGS3/assignments/04-assignment-Excel.pdf · name (e.g., cg3xzz.xlsx). Save it on your computer and in your ExcelAssignment

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 "conditionalformatting" and/or "text formulas").

1. Apply "Conditional Formatting" (under the Format menu) to the list of names on your first worksheet. The formatting should turn thebackground color of the cells (with the student's names) to red if the student is going to get an 'F' and to green if the student is going to getan 'A.' There are a couple of ways to do this; pick the one that makes sense to you.

2. Create a new column that is 1 column to the right of the list of student names. Create a formula using text formulas to take the"Firstname Lastname" from the cell to the left and change it to "Lastname, Firstname." Title this new column as Lastname, FirstnameImportant: To receive credit, we want to see a formula in this new column, not just the names reversed.

Save your extra credit files in your ExcelAssignment folder too. Name your extra credit excel files as follows:

If you attempted just the first extra credit, call it cg3xzz_extra_1.xlsx (use your own account code, of course). If you attempted just the second extra credit, call it cg3xzz_extra_2.xlsx (use your own account code, of course). If you attempted both extra credits, call it cg3xzz_extra_12.xlsx (use your own account code, of course).

Portions ©opyright 1995-2018 Mark R. Wallen, Mary ET Boyle

Adapted by Megan Bardolph for use in Cogs3 Fall 2017