23
CSCE 101 Spreadsheets with Microsoft Excel 2010 Using: Goal Seek, Macros, Filtering, and Password protection

Microsoft Excel - Computer Science & Engineeringcmatthew/101tutorials/spreadsheets.doc · Web view... by double clicking on the Excel spreadsheet icon in the desktop window or by

  • Upload
    vuanh

  • View
    225

  • Download
    0

Embed Size (px)

Citation preview

Microsoft Excel

CSCE 101

Spreadsheets with Microsoft Excel 2010

Using: Goal Seek, Macros, Filtering, and Password protection

Table of Contents

1Getting Started

1Moving Around in a Spreadsheet

2Adjusting the Size of Rows or Columns

2Adding and Deleting Rows and Columns

3A Typical Spreadsheet Application

4Formatting

4Adding Notes

5Creating Formulas

5Spreadsheet Functions

7The Automatic Formula Function

9Filling Adjacent Cells with Data or Formulas

9Formula Inconsistency

9Displaying All Formulas

10Filtering

10Goal Seek

11Making Charts and Graphs from Spreadsheets

12Selecting Non-Adjacent Cells for Graphing

12Editing a Chart or Graph

13Macros

13Recording a Macro

14Running a Macro

14Worksheet Security and Protection

14Protecting a Workbook File

15Removing Workbook File Protection

16Protecting Worksheets

16Unprotecting Worksheets

A computer spreadsheet application can contain various types of information including text, numbers, dates, and formulas. Spreadsheets facilitate efficient computation of formulas while providing organized storage for the data and the computed results. They are effective tools for many business and bookkeeping applications such as maintaining grade books, inventories, and account balances to name a few.

Getting Started

The spreadsheet application can be opened by double clicking on the Excel spreadsheet icon in the desktop window or by clicking the Start Menu > All Programs > Microsoft Office > Microsoft Excel. The spreadsheet user interface has a regular grid pattern, with numbered rows along the left side and columns across the top labeled with letters of the alphabet. The box at the intersection of a row and column is called a cell and is identified by its row and column designation. Each spreadsheet is called a worksheet. By default there are three blank worksheets in a new spreadsheet file. They can be accessed from tabs labeled: Sheet1, Sheet2, and Sheet3 at the bottom of the spreadsheet interface. Clicking on the tabs will shift from one active worksheet to another. The tabs can be given more meaningful names by double-clicking on the tab name (Sheet1, Sheet2, or Sheet3) and typing a new name, or right-click and then choose Rename. More worksheets can be inserted. Each worksheet has 8 million cells. Similar to other Office 2007 applications, Excel 2007 uses the Ribbon menu. You may refer to the Microsoft Word 2007 tutorial for more information about the Ribbon.

Moving Around in a Spreadsheet

Just click inside a cell to make it active. To highlight an entire row or column, click on the number of the row or letter of the column. All the cells will be activated. Dragging over a range of adjacent cells in any direction (over either row cells or column cells) will highlight all of them. Dragging the mouse down diagonally over several rows and columns will highlight all of them. Alternatively you can select cells with the arrow keys (up, down, left, and right) while holding down the Shift key. You can also select one cell and select another while holding all the Shift Key down to select all the cells in between.

Adjusting the Size of Rows or Columns

For widening columns, move the cursor carefully between column letters without clicking the mouse. When the cursor turns into an arrow pointing left and right, you can drag it with the mouse button held down and widen or narrow the column to any desired width.

Adding and Deleting Rows and Columns

To add a row or a column, click the mouse in the row where a new row or column is wanted, right-click, and select Insert on the pop-up menu that appears. On the dialog box that opens, select the action that you would like to perform. Similarly, you may choose Delete on the pop-up menu that appears after right-clicking on the cell. You may then choose the desired action on the Delete dialog box.

You may alternatively select Insert and Delete options on the Home command tab. Simply click on the arrow for the Insert or Delete icons on the Cells feature group and select what to insert/delete on the pop-up menu that appears.

Remember by default a spreadsheet comes with three worksheets. To add or delete a worksheet, right-click on the

worksheet tab and choose Insert or Delete.

A Typical Spreadsheet Application

Suppose that you wanted to include the following information about your next paycheck in a spreadsheet:

Monthly Income (gross) $1500

Medical Insurance$65.00

Life Insurance

$39.00

Income tax

15%

Final Monthly Check

In cell B4, we use a formula, which calculates withholding at 15% of the monthly income. All formulas start with an equal sign. The numbers used in the calculations are referred to by their cell addresses. So the formula inserted in cell B4 will be typed according to figure below.

We can now calculate the final take-home pay, based on another formula inserted in cell B5. The final pay is equal to the monthly income less all the deductions. (Final Monthly Check = Monthly Income Medical Insurance Life Insurance Income Tax) The cell addresses are used in the formula not the actual values. This allows the values in the cells to be changed and the values in the formula cells to be automatically recalculated. When that formula is typed in B5, the value of the final monthly check will be calculated and shown in cell B5. The complete spreadsheet is shown in the figures below.

The What-if analysis is the biggest advantage of using an electronic spreadsheet. All of the values can be changed and all of the calculations are recalculated automatically because the formulas refer to the values within the cell addresses not the actual values. Suppose, for example, that the next month, you get a raise to 1800 per month. You can use the same spreadsheet, since all the cells that contain numerical data are dynamic. This means that any formula, which refers to cell addresses, will use the current values in those cells in the calculations. In the formulas in B4 and B5, the monthly income is always referenced as cell B1, not the values 1500 or 1800. Given a new value of 1800 for the monthly income in cell B1, the formulas in B4 and B5 will pick it up and properly figure out new values for withholding (B4) and net monthly pay (B5).

Formatting

Formatting the data allows the cells to be represented in the appropriate context, including numbers, dates and text. To add formatting, highlight the desired cell or group of cells, right-click, and select Format Cells on the pop=up menu that appears. A dialog box will open with a list of choices for formatting cell contents.

Adding Notes

Notes are character strings that are not part of the cells but are attached to them, a kind of annotation. To add a note to a cell, select the desired cell by clicking on it. Next, right-click and select Insert Comment on the pop-up menu that appears. The program inserts a yellow box with a black border for inserting text. When you are finished inserting text, just click outside the note box and the note will no longer be visible. To activate the note, move the cursor over the cell near the tiny red spot in the upper right corner (signifying that a note is there), and the note appears temporarily.

The note feature can also be accessed by clicking on the Review tab and then clicking on the New Comment icon on the Comments feature group.

To delete a comment, select the cell containing the comment, and click on the Delete icon on the Review command tab. alternatively, you can right-click on the cell and select Delete Comment on the pop-up menu that appears.

To make inserted comments remain visible, right-click on the cell containing the comment and select Show/Hide Comment on the pop-up menu that appears. This will keep the comment box visible on the worksheet regardless of whether the cursor is placed on the cell containing the comment. To hide the comment again, right-click on the cell and select Hide Comment. The Show/Hide Comment toggle is also available on the Comments feature group of the Review command tab.

Creating Formulas

In Excel there are three ways to enter a formula: by typing it directly into a cell, by typing it into the Formula box, and by using the Automatic Formula function to create it. In our earlier example, we could easily type the two formulas directly into cells B4 and B5. Excel always uses the equal sign to start a formula. It is the equal sign, which tells the spreadsheet program that a calculation is coming in that cell, instead of a number or label or date. When you press enter, the formula will be inserted into the cell. Later, to see the formula, just click on the cell and the formula will be displayed in this formula box. If it contains an error or needs to be changed, it can easily be edited here before pressing the Enter key again.

Spreadsheet Functions

Sometimes it is not convenient to create very long formulas. For instance, to enter the following formula for 100 figures:

= (J1+J2+J3 J100) / 100

For cases like this, the spreadsheet software has already stored functions for many common operations (mathematical, statistical, and logical). One way in which you can access common functions is by clicking on the Insert Function (fx) icon next to the formula box. This will open the Insert Function dialog box. By default, the most recently used functions appear in the Select a function box. Having chosen a function, the Function Arguments dialog box appears allowing you to enter the desired arguments. In this case, the function needed is called AVERAGE, and the formula for averaging would look like the following after it is filled in with the cell addresses:

= AVERAGE (J1:J100)

Built into the function is the summing of the numbers in cells J1 to J100 and dividing them by 100, the number of elements. In a case like this with a range of cells, you specify them with shorthand of the first and last separated by a colon. The AVERAGE function can also be typed directly into the formula box with the elements inserted within the parenthesis, using the colon as a separator.

Another option for locating functions is using the Formulas command tab. You may click on the arrow for the icon of each category of functions (e.g. Logical, Financial) and a menu appears displaying common functions in that category. Select the desired function and the function shell appears in the selected cell.

The Automatic Formula Function

A feature of Excel which allows you to use functions easily is the Automatic Formula function. Let us examine the Automatic Formula function in detail.

The Function Arguments dialog box that opens after selecting a function to insert, contains a description of the formula at the bottom of the dialog box. Above that, the dialog box shows the user how to fill in the arguments. After the correct arguments are inserted, the result is displayed below the range in the menu box. If it is correct, choose OK, and the formula will be inserted into the cell.

It is possible to put literal numbers instead of addresses in the argument of a function like AVERAGE or SUM, and the formula will average them. Doing this, the user is forcing the function to work on specific numerical data rather than the value typed into the addresses, such as A1, B2, etc.

Excel has a great variety of built-in functions like AVERAGE or SUM. Perhaps you should open the Automatic Formula function dialog box and check some of them out before writing formulas for yourself. As you move through the list of functions, one click on any formula name in the dialog box will bring up a description above the Formula text box (remember that a double click brings up the formula for inserting arguments). Take a moment to look at some of these possibilities to see how they work.

You can make your own formulas. For example, suppose cell A10 looks like this: = 2+3*4. In this case, the formula is calculating with numbers, not cell addresses. A question remains: is the answer 20 (2 plus 3 times 4) or 14 (3 times 4 plus 2)? The answer is 14, since the spreadsheet follows the rules of algebra, which carries out multiplication and division before addition and subtraction. To overrule this convention, use parenthesis liberally. In other words, to get 20, the formula in cell A10 should be = (2+3)*4.

A spreadsheet cell can also be used to make logical choices for the user with the IF function. As an example of its use, consider the following case: if the price of Stock A reaches $40, then I will sell; if not, I will buy more in the next month. A condition is checked with two alternative actions. The IF function allows the spreadsheet to examine a changing condition and carry out different actions based on the changes.

The general construction of the logical IF function is as follows:

=IF(logical-condition,true-value,false-value)

To see how it works, consider the following IF function located in cell A12:

=IF(A6>A7,A11-A10,0)

The function will compare the values in cells A6 and A7. If the value in A6 is greater than the value in A7, then the true case applies and the value in A10 will be subtracted from the value in A11. The result will be placed in cell A12, where the IF function is located. If the value in A6 is not greater than the value in A7, then the value 0 will be placed in the A12 cell.

The three part IF function can be understood in logical terms:

IF the value in A6 is greater than the value in A7

THEN subtract the value in A10 from the value in A11 and place the result in cell A12

ELSE put zero in A12

IF function makes the spreadsheet a very powerful tool for making logical choices by having the ability to test and choose what to do next depending on the results of the test.

In a large and complex spreadsheet, a good rule of thumb is to consider adding a note to a cell containing any complicated formula to remind yourself what you were intending when the formula was created. Several weeks and hundreds of cells later, you may look at this cell and forget what it is supposed to be calculating. The text note will be a reminder of the thinking which created it. Remember that we used a note in the take-home pay example which introduced the discussion of spreadsheets.

Filling Adjacent Cells with Data or Formulas

One of the most useful features yet to discuss with spreadsheets is the concept of filling adjacent cells with data of formulas rather than typing or cutting and pasting them manually. For instance, suppose that you have a cell, D6, with a number 10 in it. The next several cells from D7 to D10 should be increased by 10 each so that D7 will have 20 in it and D10 will have 50. A shortcut to typing all this involves filling. First put the formula =D6+10 in cell D7. That will take care of the 20 which goes there. With that cell highlighted, place the cursor on the bottom-right corner of the highlighted cell till you see a crossbar. Drag the mouse over all the cells through D10. When you release the mouse, the formula will be applied to all the cells, making each 10 larger than the one above.

An even quicker solution to this example uses the automatic fill handle. First put a 10 in cell D6 and a 20 in D7. Then select both of these cells with the mouse. You can grab the fill handle on the bottom-right corner of D7 as explained above and drag it down through cell D10. When you have finished, all cells will have the correct numbers, each one being 10 greater than the one above it. The program recognizes the relationship between the first two cells (the increment of 10) and continues to apply it across the whole range. This will work with more complex relationships or with a single value. If you need a column with all of the values equal to 100, you can type 100 in the first cell and drag the fill handle down to fill the other cells.

Formula Inconsistency

If a formula is inconsistent with other formulas in nearby cells the inconsistent formula will be flagged with a little green triangle in the upper left corner of the cell. When the cell is selected the AutoCorrect Options button appears. If you click the button, a menu opens with more options including copying the formula from other cells, correcting errors in formulas, and ignoring the inconsistency.

Displaying All Formulas

Use Control+ ~ to display all of the formulas on the spreadsheet instead of the values. You can then edit the formulas. Press Control+ ~ again to return to the calculated values.

Filtering

To use the filter feature of Excel, first select the category or categories according to which you would like to filter a set of data. For example, Name, Artist, Year, and Genre can be used as filtering criteria for data about music records. Click on any of these categories and do the following to activate the filter.

1. On the Home command tab, click on the arrow for the Sort & Filter icon, and select filter on the pop-up menu that appears. You will notice a small dropdown arrow over the selected criteria cell(s).

2. Using the drop-down arrow, choose the category of information to filter. The first choice, Select All, is the default and simply means all category values will be displayed. You may uncheck the box for Select All and any other values that you do not want to be displayed. In the example below, we use Pop as the desired value for the Genre filtering criteria.

3. Click OK.

4. You will notice that all only the music records which belong to the pop genre remain visible. You will also notice that a funnel icon appears next to the drop-down arrow for Genre. This means that Genre is being used as a filtering criterion.

5. You can also apply a Number Filter to a column that contains numbers rather than text. To filter years more recent than 2004 you would first click on the filter for the column Year. After clicking on the drop-down arrow of the filter, hover over Number Filters and select Greater Than. In the text box to the right of is greater than enter 2004. The result would show only rows with a year more recent than 2004.

6. To remove the filter, click on the drop-down arrow (and funnel) icon for Genre, and select Clear Filter From Genre on the pop-up menu that appears.

Goal Seek

Another powerful feature of Excel is Goal Seek. Before seeing it in action, let us look at a situation where it is used. Suppose that you are trying to sell 100 computers, fifty of which cost you $400 apiece and the other fifty which cost $500 apiece, and want to make a profit of $50,000. What price should you sell them for? Goal Seek is the ideal for any situation in which you know the desired result, a profit of $50,000 in this case, before you known one important item that is needed to achieve the result, the sales price for each computer. The relationships between the elements are known:

50 * (sales price 400) + 50 * (sales price 500) = 50000

In the spreadsheet, the formula needs to be placed in one cell, and another needs to be selected for the unknown value, the sales price. For instance, cell A1 could contain the formula, with cell B1 chosen for the unknown sales price. The formula above is then typed in A1 as follows:

=50 * (B1 400) + 50 * (B1 500)

To access Goal Seek, click on the Data command tab and then click on the arrow for the What-If Analysis icon on the Data Tools feature group. On the pop-up menu that appears, select Goal Seek.

On the Goal Seek dialog box, you will see the following three boxes: Set Cell, To Value, By Changing Cell. In the Set Cell box, enter A1, this is our formula cell. In the To Value box, enter 50000, the target value. Finally, enter B1 in the By Changing Cell box. Cell B1 is where the unknown value will go. After all of these are inserted and the OK button is clicked, the program returns a message that Goal Seek worked. The unknown value is 950. In other words, if all 100 computers are sold at $950, the profit will be $50,000. This feature offers a powerful tool to someone who knows the bottom line of some process but is missing a key component of the process. After it is set up, Goal Seek also allows one to change the bottom line quickly and see the results.

Making Charts and Graphs from Spreadsheets

Charts and graphs can be made in Excel from data in a spreadsheet. To create a chart, to the following.

1. Highlight the cells that contain the data to be used to create the chart. It is a good idea to organize the data to be charted in a column-oriented manner in which each column represents a different category of data similar to what was shown in the Filtering and Sorting section. Do not highlight the column headings. E default, the data in the left-most column will be used for the horizontal (x) axis of the chart and any additional columns will be used for the vertical (y) axis of the chart.

2. Click on the Insert command tab and click on the arrow for the icon representing the category of chart you want to create.

3. On the pop-up menu that appears, select the specific type of chart you would like to use. The chart is created with the default format settings. (See next page)

4. In the legend, you will notice that each category of data used for the vertical axis is given a name starting with the word Series. The is the default naming convention used by Excel.

5. To change the names used for the data series, click on the chart, and three additional command tabs will appear. Click on the Design command tab.

6. Click on the Select Data icon and the Select Data Source dialog box will open.

7. In the Legend Entries (Series) box, select the series which you would like to rename, click the Edit icon, and the Edit Series dialog box will open.

8. Place the cursor inside the Series Name box and then click on the worksheet cell containing the text you would like to use as the name for the series.

9. Click OK on the Edit Series dialog box and OK on the Select Data Source dialog box.

Selecting Non-Adjacent Cells for Graphing

You may need to graph cells that do not lie adjacent to each other in a spreadsheet. Click in the first cell, then hold down the Control key, and click on the other cells to select, wherever they are in the worksheet. When you have finished, you will have selected a group of nonadjacent cells that can be graphed.

Editing a Chart or Graph

Often you forget something or need to make changes once a graph has been created. Excel has options to allow further editing after the graph is created. Simply select the chart to be edited and three additional command tabs, namely Design, Layout, and Format will appear. Click on each of the tabs to view the available chart formatting options.

Macros

If you perform a task repeatedly in Microsoft Excel, you can automate the task with a macro. A macro is a series of commands and functionsthat are stored in a Microsoft Visual Basic moduleand can be run whenever you need to perform the task. For example, if you often enter long text strings in cells, you can create a macro to format those cells so that the text wraps within the cell.

Recording a Macro

1. On the View command tab, click on the Macros icon.

2. Select Record Macro on the pop-up menu that appears and the Record Macro dialog box will open.

3. In the Macro name box, enter a name for the macro. The first character of the macro name must be a letter. Other characters can be letters, numbers, or underscore characters. Spaces are not allowed in a macro name; an underscore character works well as a word separator. Do not use a macro name that is also a cell reference or you can get an error message that the macro name is not valid.

4. If you want to run the macro by pressing a keyboard shortcut key, enter a letter in the Shortcut key box. You can use CTRL+ letter (for lowercase letters) or CTRL+SHIFT+ letter (for uppercase letters), where letter is any letter key on the keyboard. The shortcut key letter you use cannot be a number or special character such as @ or #. The shortcut key will override any equivalent default Microsoft Excel shortcut keys while the workbook that contains the macro is open.

5. In the Store macro in box, click the location where you want to store the macro. If you want a macro to be available whenever you use Excel, select Personal Macro Workbook.

6. If you want to include a description of the macro, type it in the Description box. Click OK.

7. Perform all the tasks that you want to record.

8. If you want the macro to run relative to the position of the active cell, record it using relative cell references. To do this, before you start recording a macro, select Use Relative References on the pop-up menu that appears when you click on the Macros icon.

9. Select Stop Recording on the pop-up menu that appears when you click on the Macros icon once you are finished.

Running a Macro

1. Open the workbook that contains the macro.

2. On the View command tab, click on the Macros icon and select View Macros on the pop-up menu that appears.

3. In the Macro name dialog box, you will see a list of all recorded macros. Select the name of the macro you want to run.

4. Click Run. If you want to interrupt, press ESC.

5. If you have assigned a shortcut key to the macro, simply use the shortcut. There is no need to use the Macros icon.

Worksheet Security and Protection

Microsoft Excel provides several layers of security and protection to control who can access and change your Excel data. For optimal security, you should protect your entire workbook file with a password, allowing only authorized users to view or modify your data. For additional protection of specific data, you can protect certain worksheet or workbook elements, with or without a password. Use element protection to help prevent anyone from accidentally or deliberately changing, moving, or deleting important data.

Protecting a Workbook File

You can help secure an entire workbook file by restricting who can open and use its data and by requiring a password to view or save changes to the file. Follow the steps below to set the passwords for file access and modification.

1. Click on the Office button and on the pop-up menu that appears, click on Save As and choose the file format to be used when saving the file.

2. On the Save As dialog box that opens, click on Tools, and select General Options on the pop-up menu that appears.

3. On the General Options dialog box, enter a password for opening and modifying the workbook. The password for opening the workbook is encrypted to help protect your data from unauthorized access. The password for modifying the workbook is not encrypted and is only meant to give specific users permission to edit workbook data and save changes to the file. When you are done entering the desired password(s), click on OK. After you click on OK, you will get an additional pop-up box for each password asking you to re-enter the password again. Retype the passwords and click OK.

4. On the Save As dialog box, click on Save.

5. The file is now protected. Save the file, close it, and re-open it to ensure that the passwords work properly. When opening the file, you will first be asked to enter the password to open/view the file and then asked to enter the password for modification.

Removing Workbook File Protection

To remove the password protection for a file, you must first have the passwords required to access and modify the file. The removal of password protection is almost identical to the process of protecting the file.

1. Repeat steps 1 and 2 used for protecting a workbook.

2. On the General Options dialog box, delete the password(s) for the type of protection you want to remove, and click OK.

3. Click Save on the Save As dialog box to save the file.

Protecting Worksheets

To prevent anyone from accidentally or deliberately changing, moving, or deleting important data, you can protect certain worksheet or workbook elements, with or without a password. To protect worksheet elements, follow the steps below.

1. Switch to the worksheet you want to protect.

2. Unlock any cells you want users to be able to change. To do this, select each cell or range,

3. Right-click on the cell(s) and select Format Cells on the pop-up menu that appears. Click on the Protection tab, and then clear the Locked check box.

4. Hide any formulas that you don't want to be visible. To do this, right-click on the cell(s) and select Format Cells on the pop-up menu that appears. Click on the Protection tab, and then select the Hidden check box.

5. On the Review command tab, click on the Protect Sheet icon on the Changes feature group and the Protect Sheet dialog box will open.

6. Type a password for the sheet. Make sure that the top checkbox is selected. In the Allow all users of this worksheet to list, select the elements that you want users to be able to change.

7. Click OK. If prompted, retype the password. Save the file.

Unprotecting Worksheets

To unprotect a worksheet that has been password-protected, do the following:

1. When a worksheet is protected, you will see the Unprotect Sheet icon on the Review command tab instead of the Protect Sheet icon. Click on the Unprotect Sheet icon.

2. A pop-up box labeled Unprotect Sheet will appear asking you to enter the password.

3. Enter the password and click OK. The worksheet is now unlocked and can be modified.

4. If you want to protect the worksheet again, repeat the steps outlined in the previous section.

The Ribbon

Worksheets

Cell

Formula Box