Excel Project 5

advertisement
Excel Project 5
Creating Sorting, and Querying a Worksheet Database
A Microsoft Excel table can function as a simple database (organized collection of data). When an
individual or small business needs to perform database functions, Excel can often handle it, negating the
need for expensive database software. In this exercise you will learn to use some of Excel’s database
capabilities as well as some terminology.
1. Open a blank Excel worksheet.
2. Use the mouse to change column widths as follows: A = 9.00, B = 7.00, C = 7.00, D = 5.00, E =
5.00, F = 10.00, G = 5.00, H = 10.00, I = 11.00, J = 11.00, K = 11.00, and L = 7.00
3. Click cell A7 and then enter Skatejam Sales Representative Database as the worksheet
database title. Rows 1-6 will be left blank to hold the results of database queries.
4. Change the title font to size 14, Bold, and Green. Change the row height to 18.00.
5. Enter the column titles in row 8 as shown. Change the height of row 8 to 15.00.
6. Select the range A8:J8. Bold the range. Right click on the range and select Format cells.
7. Apply a heavy green bottom border to the range.
8. Select columns C, D, E, G, and L. Click the Center alignment button so that future entries will be
centered.
9. Right-click the column F heading. Select format cells.
10. Click the Number tab and click Date in the category list box. Scroll down in the Type box and then
click 3/14/1998 to display the future date entries with four-digit years. Click OK.
to the selected range. Click the Decrease
11. Select columns I and J. Apply the Comma style
decimal button twice so that all future numeric entries in these columns display using the Comma
style with zero decimal places.
12. Rename Sheet 1: Sales Rep Database.
13. Save the file to your network drive as Skatejam Database.
Although Excel usually can identify a database range when you invoke a database-type
command, assigning the name Database to the range eliminates any possible confusion when
commands are entered to manipulate the database.
14. Select the range A8:J9. Click in the Name box and type Database as the name
range. Press <Enter>.
15. Click in cell A9 to deselect the range. Click Data on the menu bar and
select Form to display the data entry form shown to the right. Excel
generates the form automatically from the row titles in your worksheet
that will serve as field names.
16. Type in the data shown at the right for the first record. Use the <Tab>
key to move to the next field or <Shift>+<Tab> to go back. When
finished, click the New button to enter the data and get a blank form for
the next record.
17. Type the data for the remaining 11 employees using the data entry
form, using the data shown in the next figure. Click the Close button
after entering the last record. Your database should look like the figure.
Excel Project 5 – Page 1
for the
You could also create the database by entering the records in columns and rows as you would enter
data into any worksheet and then assign the name Database to the range A8:J20 after completion.
The data form was used here because it is considered a more accurate and reliable method of data
entry, which automatically extends the range of the name Database as you add records.
Adding Computational Fields to the Database
The next step is to add the computational fields % of Quota in column K and Grade in column L.
Then the name Database must be changed from the range A8:J20 to A8:L20 so that it includes the
two new fields.
18. Select cell K8 and enter: % of Quota.
19. In cell L8 enter: Grade.
20. Click cell J8. Click the Format Painter button
apply the format.
21. In cell K9 enter the formula: =J9/i9.
, then drag the mouse through cells K8:L8 to
22. Click cell K9 and then click the Percent Format button
. Click the Increase decimal
twice to display two places to the right of the decimal point.
23. Use the fill handle to copy the formula and format in K9 to the range K10:K20.
button
The entries in the % of Quota column give the user an immediate evaluation of how well each sales
rep’s YTD Sales are in relation to their annual quota.
Excel has two lookup functions that are useful for looking up values in tables, such as tax tables,
discount tables, parts tables, and grade scale tables. Both functions look up a value in the table and
return a corresponding value from the table to the cell assigned the function. These are HLOOKUP
(Horizontal Lookup) and VLOOKUP (vertical lookup). The general form is similar for both:
=VLOOKUP( search argument, table range, column number).
24. In cell N1 enter: Grade Table. Click the Bold button.
25. Select cells N1 and o1. Click the Merge and center button to
center the title over both columns. Apply a thick green bottom
border to cells N2:o2.
26. Enter the column titles and table entries shown in the figure to
the right in the range N2:o7.
27. Increase the width of columns N and O to 10.00.
28. Click cell L8. Click the Format Painter button. Drag the mouse
through cells N2 and o2 to apply the same format to the
column titles in the grade table.
29. Select the range N3:o7 and click the Center Alignment button.
Your Grade table should look like the figure to the right at this point.
30. In cell L9 type the VLOOKUP formula: =VLOOKUP( K9, $N$3:$o$7, 2).
Excel Project 5 – Page 2
The VLOOKUP function will look at the value in K9, compare it to the values in the first column of
the grade table, and display the Grade value found in column 2 of the grade table in cell L9. An A
should appear in cell L9 since K9 contains 93.35%.
31. Use the fill handle to copy the formula in cell L9 to the range L10:L20. Notice that the range listed
for the table is an absolute reference to keep the reference the same when the formula is
copied. Your table should look like the one pictured below. Save your work.
As shown in the figure above, any % of Quota value below 60 returns a grade of F. Grades are
assigned based on the lookup grade table you created.
Redefining the Name Database
The final step in adding the two computational fields to the database is to redefine the name
Database so that the computational columns are included in the named range.
32. Click cell A22 so that no range is selected.
33. Click Insert on the menu bar and select the Name submenu. Select define on the name submenu.
34. When the Define Name dialog box appears.
Click Database in the Names in workbook
list (see figure at right).
35. In the Refers to: box change the letter J to
L to include the two additional columns in
the Database.
36. Click OK to complete the redefinition.
37. Click the Name box arrow on the left side of
the formula bar and then select Database.
This should cause the entire range A8:L20
to be selected if you have done this
exercise correctly.
38. Click outside the range to deselect it. Save
your work.
Guidelines to follow when creating a database in Excel
A. Database Size and Workbook Location
• Do not enter more than one database per worksheet.
• Maintain at least one blank row between the database and other worksheet
entries.
• Do not store other worksheet entries in the same rows as your database.
• Define the name Database as a database range.
• A database can have a maximum of 256 fields and 65,536 records on a
worksheet.
B. Column Titles (Field Names)
• Place column titles in the first row of the database.
• Do not use blank rows or rows with dashes to separate the column titles (field
names) from the data.
• Apply a different format to the column titles and the data for ease of reading.
Excel Project 5 – Page 3
•
Column titles can be up to 32,767 characters in length. The column titles
should be meaningful.
C. Contents of a Database
• Each column should have similar data. For example, Employee Hire Date
should be in the same column for all employees.
• Format the data to improve readability, but do not vary the format of the data in
a column.
Using a Data Form to View Records and Change Data
At any time while the worksheet is active, you can use the Form Command on the Data menu to
display records, add new records, delete records, and change the data in records. When a data form
is opened initially, Excel displays the first record in the database. You can use the Find Next and Find
Prev buttons to navigate through the database. The New and Delete buttons are used to add or
delete records respectively.
To change data within a record simply display it and edit the affected field.
Sorting a Database
Often data is easier to work with if sorted in a particular order. This is very easy to do in Excel.
on the toolbar. This automatically sorts the
39. Click in cell A9. Click the Sort Ascending button
database into alpha order by the Lname field.
40. While still in cell A9, click the Sort Descending button. This reverses the sort order for the
database.
41. Click in cell F9 and then click the Sort Ascending button to return the database to its original order
(Data was entered is ascending order by hire date).
Sorting a Database on Multiple Fields
Excel allows you to sort on a maximum of three fields (sort within a sort). For instance, if you had
two employees with the same last name you would need a secondary sort by first name to get a true
alpha order listing of your database. To do this you must use Sort from the Data menu rather than the
shortcut buttons.
42. Click any cell within the database.
43. On the Data menu select Sort.
44. When the Sort dialog box appears choose the fields shown
at the right to sort by Gender, then by Educ, then by Quota.
To sort a database on more than three fields, you must sort the
database two or more times. The most recent sort take
precedence. Hence, if you plan to sort on four fields, you sort on
the three least important keys first and then sort on the major
key.
Excel Project 5 – Page 4
Displaying Automatic Subtotals in the Database
Displaying automatic subtotals is a powerful tool for summarizing data in a database.
45. Select cell G9. Click the Sort Ascending button. This
creates the fields upon which subtotals will be based, the
state.
46. Select Subtotals from the Data menu.
47. When the Subtotal dialog box displays, click the At each
change in box arrow and select St. If necessary, select Sum
in the Use function list box. In the Add subtotal to: box
check only Quota and YTD Sales as shown at the right.
Click OK. Excel calculates and inserts the subtotals for the
selected fields grouped by state. Your worksheet should
look like the one pictured below.
48. Click the Zoom box
on the Standard toolbar and type 90 in the box. Press <Enter>.
49. Select columns I and J. Double-click the right boundary of column heading J to set these columns
to optimum width. Select cell G9 to deselect the columns.
at the top-left of
50. Click the Row level 2 symbol
your worksheet. Excel hides a;; detail rows and
displays only the subtotals as shown at the right.
51. Click the row level 1 symbol, only the grand total will
show.
52. Click the row level 3 symbol to show all data. Change
the widths of columns I and J back to 11.00.
53. Select rows 1-27 of your worksheet. Copy and paste
the selected range onto Sheet 2 of your worksheet. Adjust column widths on sheet two as needed
to display all data. Rename Sheet 2 as: Subtotals by State. Click on the Sales Rep Database
tab to return to the original sheet.
54. Removing the subtotals: From the Data menu select Subtotals. Click the Remove All button when
the Subtotal dialog box displays. Your worksheet should return to normal (similar to the top of
page 3).
55. Sort the database by hire date to return records to their original order. Save your work.
Excel Project 5 – Page 5
Finding Records Using a Data Form
Once you have created a database, you might want to view records that meet only certain
conditions, or comparison criteria. Displaying records that meet the criteria is called querying the
database.
56. From the Data menu select Form.
57. Click the Criteria button on the form. Excel clears the field values giving you a blank form.
58. Enter M in the Gender text box, >=42 in the Age text box, Inside in the Sales Area text box, and
>2,600,000 in the Quota text box. Click Find Next. The record for Kevin James should appear.
59. Use the Find Next button to see if any other records meet the criteria (Thomas Ryan does).
60. When you are finished displaying the records meeting the criteria, close the data form.
If you are querying on text fields, you can use wildcard characters to find records that have certain
characters in a field. Excel uses the two wildcard characters, the question mark (?) and the Asterisk
(*) in a way similar to their original use in the MS-DOS operating system. The question mark
represents any single character in the same position as the question mark. For example, entering
Ry$n would find all of the following: Ryan, Ryon, Ry2n, Ry%n, etc. An asterisk can be used to
represent any number of characters in the same position as the asterisk. Examples: Jo* would find all
entries beginning with Jo; ey would find all entries ending in the letters ey; Ch*g would find all entries
beginning in Ch and ending in g no matter how many characters are in between.
Filtering a database using AutoFilter
An alternative to using a data form to query is to use AutoFilter. Whereas the data form displays only
one record at a time, AutoFilter displays all records that meet the criteria as a subset of the database.
61. Select any cell in the database. From the Data menu select Filter. Select AutoFilter from the Filter
submenu. AutoFilter arrows will appear to the right of each filed name as shown below.
62. Click the Gender arrow and select F. In the State filed click AZ. Now only the records for females
from Arizona appear. There should be 2 records. Copy and paste rows 1-18 onto sheet 3.
Rename Sheet 3 as Females from Arizona.
63. Return to the Sales Rep Database sheet and from the Data menu select Filter – Show All – to
see all records again.
64. Next you will add a sheet to your workbook. From the Inset menu select Sheet. A blank sheet will
be inserted into the workbook. If necessary, drag the tab for the new sheet to the right so that it is
the last sheet in the workbook.
Using Custom Criteria
65. Select cell A9. Click the Age arrow and then select
(Custom…).
66. When the Custom AutoFilter dialog box appears, fill it
in as shown in the figure to the right. Click OK. Five
records should appear.
67. Copy and paste rows 1-14 onto the blank sheet and
rename it as: 38-52. Adjust column width as needed.
68. Return to the Sales Rep Database sheet. From the
Data menu select Filter – AutoFilter to turn AutoFilter
off and display all records. Save your work.
Excel Project 5 – Page 6
Using a Criteria Range on the Worksheet
Rather than using a data form or AutoFilter to establish criteria, you can set up a criteria range
on the worksheet and use it to manipulate records that pass the comparison criteria. Using a criteria
range on a worksheet takes two steps: a) Create the criteria range and name it Criteria; b) Use the
Advanced Filter command on the Filter submenu.
69. Select the range A7:L8 on the Sales Rep Database sheet. Copy and paste this range into cell A1
on the same sheet. This insures that the field names in the criteria area match the database field
names.
70. Click cell A1 and type: Criteria Area to replace the old title.
71. In cell C3 enter: F
72. In cell D3 enter: >34
73. In cell L3 enter: >B
74. Select the range A2:L3. Click the name box in the formula bar and then type Criteria as the
range name. Press <Enter>. Click cell A9 to deselect the range.
75. From the Data menu select Filter – Advanced Filter. Click OK when the Advanced Filter dialog
box appears. Two Reps meet the criteria, Female, over 34 with a grade grater than B. Greater
than and Less than use alpha order to determine their truth value. Therefore C > B.
76. Insert a blank sheet into your workbook (see step 64). Drag it to the right if necessary. Copy rows
1-14 from the Sales Rep Database sheet and paste them onto the new sheet. Adjust column
width as needed. Name the sheet F>34>B.
Extracting Records
If you select the Copy to Another location option button in the Action area of the Advanced filter
dialog box, Excel copies the records that meet the comparison criteria to another part of the
worksheet, rather than displaying them as a subset of the database. To use this feature you must set
up an Extract Range ( a place to copy to).
77. Make sure you are on the Sales Rep Database sheet and that all records are visible. Select the
range A7:L8. Copy and paste the range into cell A24.
78. Click cell A24 and type Extract Area to change the title.
79. Select the range A25:L25. Type Extract in the name box to name the range. Click cell A20 to
make sure the database is active.
80. From the Data menu select Filter –Advance Filter. When the dialog box displays, be sure Copy to
another location is checked and then click OK. The Extract area should look like the one below:
Save your work.
Using Database Functions
Excel has 13 database functions that you can use to evaluate numeric data in a database. One of the
functions is called DAVERAGE. As the name implies you use DAVERAGE to find the average of
numbers in a database field that pass a test. In this exercise you will also use the DCOUNT function
to count the number of sales reps that have a grade of A.
81. Click cell Q1 and enter Criteria for DB Functions. Select the range Q1:S1 and then click the
Merge and Center button to center the title across the range. Click the Bold button to bold the
title.
82. Select cell Q2 and enter Gender as the field name.
83. Select cell R2 and enter Gender as the field name.
Excel Project 5 – Page 7
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
Select cell S2 and enter Grade.
Select cell L8. Click the Format Painter button. Drag through cells Q2:S2 to apply the format.
In cell Q3 enter F. In cell R3 enter M. In cell S3 enter A.
In cell Q5 enter: Average Female Age = = = = =>.
In cell Q6 enter: Average Male Age = = = = = = =>.
In cell Q7 enter: Grade A Count = = = = = = = = =>.
In cell T5 enter the formula: =daverage(database, “Age”, Q2:Q3).
In cell T6 enter the formula: =daverage(database, “Age”, R2:R3).
In cell T7 enter the formula: =dcount(database, “Age”, S2:S3)
Format cells T5 and T6 to Number showing two decimal
places.
94. The Functions area should look like the figure to the right.
Save your work.
Entering Formulas in the Template
The most difficult formula to understand on this worksheet is the
one to calculate Average Unit Price, which could be called
average selling price. To make a net profit, companies must sell their merchandise for more than the
unit cost plus the company’s operating expenses (taxes, warehouse rent, etc.). To determine what
selling price to set for an item, companies often first establish a desired margin. Most companies
operate on a margin of 60% - 75%. Home entertainment Systems uses a margin of 65%.
95. In cell D5
Submit you finished file to JCPS Online for grading. DO NOT PRINT.
Excel Project 5 – Page 8
Download