Database
Database
þ beginner
1
Databases
Overview
Databases are used to store information that can then be easily extracted. A telephone book is an
example of a database containing names, addresses and phone numbers. Excel has excellent
database management features. Unlike prior versions of Excel, you can have more than one
database per worksheet, but it is difficult. You need to define ranges for each database. I
recommend just having one database per worksheet, adding more worksheets if necessary.
Here is a database for an imaginary local dentist. His patients are listed along with the type of
service rendered and the date of service. The cost of the service is listed, along with the amount
past due. If the service was more than 30 days ago, then the amount is past due.
At the top of each column is a row of Field Headings (Last Name, First Name, etc.) These are
required elements. There must not be a row of empty cells below the headings.
The thing you want to be able to do with a database is to extract information from the large
list of data. To do this, we choose Data–Filter–AutoFilter.
If your active cell is any cell in the database (a cell below the field headings) then the
database will be automatically recognized by Excel.
If, however, the active cell is a cell outside of the database data (say an empty cell or one
above in the header), then Excel won’t know where the database is and will ask you to find
it.
2
So, click in any cell that is part of your database and Choose Data–Filter–AutoFilter. The
field headers will change in appearance, acquiring little drop-down arrows next to their
names.
Once you are at this step, you are ready to start extracting data. Hold down your arrow on
one of the pull-down field header arrows and you will see a list of criteria found in that
field. Below is the list of criteria you can select to extract data from the Service field:
In my example, I have chosen to extract records for people who had an exam, so I dragged
down to Exam and let go. Immediately the database contracts to show only the records of
people who fit this criteria.
3
You may want to extract records that fit two criteria. For example, let’s say that we want to
find everyone that came in for either an exam or to have their teeth cleaned. In this case,
you would choose (Custom) from the list of Service criteria.
I typed Clean* so that I can find everyone who has “Clean” in their service, including:
clean, cleaning, cleaned, cleaning & exam, etc. The results are shown below:
As you can see from the row headings above, the database contracts to hide all the records
that don’t fit the criteria. Once you’ve gotten this list, it might be a good idea to copy it and
paste it onto a separate worksheet if you think you’ll need it again. Otherwise you’ll have
to re-find it all again.
When you’re done working on the database and want to return it to a regular spreadsheet
without those little drop-down arrows, simply choose Data-Filter-AutoFilter again. This is
an on/off switch.
4
If you work a lot with the database feature, you may find it easier to enter your data using
the database form.
Choose Data-Form… If necessary, click on the New button to access a new record. Type in
the information, tabbing between fields. Click on the New button to go to a new record.
When you’re done, click on the Close button.
By the way, I’d like to point out that in the form shown above, you don’t enter in an
amount for Past Due. That’s because this amount is automatically generated by Excel. It is
an IF formula: =IF(D11+30<$C$5, E11,0). Deciphered, this means that if the date of service
was 30 days prior to today’s date, then the amount due = amount past due. If not, then
nothing is overdue ($0) yet.
This database uses the current date to figure out whose bill is overdue. It would be
cumbersome if every day you worked on the database, you had to remember to type in
today’s date before you started working. So the amount in Cell C5 isn’t really today’s date
(although it looks like it). It is really a formula that will automatically insert the current
date into the cell (assuming that the date is correctly set on the computer). The formula for
this is =NOW().
5
SORTING
Eventually you’ll probably want to sort data. The sorting feature works the same whether
you’re working on a database or just a regular worksheet.
With one of the cells in the list the active cell (just click your cursor in any cell of the table),
choose Data–Sort…. You’ll get the dialog box shown above. Also, your database will be
selected in the background.
First, choose which column you want to sort by. Place your arrow on the little up/down
arrow next to the Sort by box and hold down the mouse button. A list will appear. Drag
down to what you want sorted by.
If you want to sort by more than one field, choose the second field in the next area. If you
have column headers (you will if it’s a database), click the appropriate button under My
List Has: Header Row/No Header Row. When you’ve made your choices, click the OK
button and the data will be sorted.
Once you’ve done a sort, there is no magic button to push to go back to the original order.
If you want to be able to do that, before sorting the first time, insert a new Column A.
Number each row (use AutoFill here). Then, after sorting by, say, last name, you can go
back to the original order by sorting again, choosing Column A to sort by.