When you need to store a lot of the same type of information in a worksheet, you can create a database in a table. For example, if you run a business, you can make a database of your customers and their orders.
The first step is to set up the table and to tell Excel that you're creating a table rather than a regular worksheet. The next step is to add your data to the table, either by typing it into the cells as usual or by using a data-entry form.
Once the data is in the table, you can sort the table to reveal different aspects of its contents or filter it to identify items that match the criteria you specify.
Before you start creating a table in Excel, it's important to be clear about what you can and can't do with Excel tables.
As you know, an Excel worksheet consists of rows and columns. To create a table on a worksheet, you make each row into a record—an item that holds all the details of a single entry. For example, in a table that records your sales to customers, a record would contain the details of a purchase. You make each column a field in the table—a column for the purchase number, a column for the date, a column for the customer's last name, and so on. Figure 10–1 shows part of an Excel table for tracking sales to customers.
Figure 10–1. An Excel database consists of a table, with each row forming a record and each column containing a field.
This is what's called a flat-file database: all the data in the database is stored in a single table rather than in separate tables that are linked to each other.
This means you can use Excel to create any database for which you can store all the data for a record in a single row. Because you have a million rows at your disposal, you can create large databases if necessary, but they may make Excel run slowly.
What you can't do with Excel is create relational databases—ones that store the data in linked tables. A relational database is the kind of database you create with full-bore database applications such as FileMaker, Microsoft Access (on Windows), Oracle (on various operating systems), or SQL Server (on Windows). In a relational database, every record has a unique ID number or field that the application uses to link the data in the different tables.
In this section, you'll look at how to create a table and enter data in it either by using standard Excel methods or by using a data-entry form.
To create a table, follow these steps:
File
New Workbook
from the menu bar.File
New from Template
, then make your choices in the Excel Workbook Gallery dialog box.NOTE: Usually, it's easiest to put the headings in the first row of the worksheet, but if you need to have information appear above the table, leave rows free for it.
Tables
Table Options
New
from the Ribbon, clicking the main part of the New button rather than the pop-up button. Excel makes the following changes:NOTE: If your headings have the same formatting as the data rows, choose Tables
Table Options
New
Insert Table with Headers
rather than Tables
Table Options
New
. Otherwise, Excel inserts a new row containing headers above your heading row. If your table doesn't have headers, choose Tables
Table Options
New
Insert Table without Headers
.
At this point, you can start entering data in the table (as discussed next)—but before you do, you may want to change the way it looks. To do so, follow these steps:
Figure 10–2. You can format a table quickly by applying one of Excel's table styles from the Table Styles panel on the Tables tab of the Ribbon. Scroll down the panel to see the other styles.
Figure 10–3. Adding a Total row to a table lets you quickly insert functions in the row's cells. Excel changes the header row to column labels when you scroll down the worksheet.
TIP: The pop-up menu in the Total row of a table gives you instant access to the most widely used functions in databases—Average, Count, Count Numbers, Max, Min, Sum, StdDev (Standard Deviation), or Var (calculating variance based on a sample). You can also click the More Functions item at the bottom of the pop-up menu to display the Formula Builder, from which you can access the full range of Excel's functions. For example, you can insert the COUNTBLANK() function to count the number of blank cells in a column. You might do this to ensure that a column of essential data contains no blanks.
When you've finished choosing a style and options for the table, save your work as usual.
You can enter data in a table either by typing it in directly or by using a data-entry form. In most cases, the data-entry form is the easier option, as you'll see in a moment. You can also connect a table to an external data source, as discussed in the following section.
A table is essentially an Excel worksheet at heart, so you can enter data in the table by using the standard techniques you've learned in the past few chapters. For example, click a cell, then type data into it; or, if you have the data in another worksheet, copy it and paste it in.
When you enter data in the row immediately after the last row in the table, Excel automatically expands the table to include that row. To add a row within the table, click a cell in the row above which you want to add the new row, then choose Insert
Rows
from the menu bar. Again, Excel automatically expands the table to include the new row.
To insert a column in the table, click a cell in the column before which you want to add the new column, then choose Insert
Columns
from the menu bar. Once more, Excel automatically expands the table.
TIP: You can quickly select a row, a column, or an entire table with the mouse. To select a row, move the mouse pointer to the left part of a cell in the table's leftmost column, then click with the horizontal arrow that appears. To select a column, move the mouse pointer over a column heading, then click with the downward arrow that appears. To select the whole table, move the mouse pointer over the upper-left cell in the table, then click with the diagonal arrow that appears.
Typing directly into the table tends to be awkward, especially when the table contains too many columns to fit in the Excel window with the whole content of each column displayed. When your database has grown beyond a few rows, you can usually enter data more easily by using a data-entry form—a dialog box that Excel automatically tailors to suit your table.
Choose Data
Form
to display the data-entry form dialog box. Figure 10–4 shows this dialog box, whose title bar shows the name of the worksheet you're using (here, Sales) rather than the word Form.
Figure 10–4. The Form dialog box bears the name of the worksheet your table is on (here, Sales) and shows all fields in the order they appear in the header row.
To use the data form, you move to the record you want in one of these ways:
Excel automatically switches the dialog box back to Form view when you search. If you decide you don't need to search after all, click the Form button (which replaces the Criteria button) to return to Form view.
Once you've created or located the record you want to change, type or edit the data in the fields in the data-entry form dialog box. Excel enters it in the columns for you.
When you've finished using the Form dialog box, click the Close button to close it.
If you have your data in an external data source, such as a relational database, you can import the data into an Excel table to work with it. You can then refresh the data in the Excel table with the latest data from the database.
To connect to a relational database, such as a Microsoft Access database or an Oracle database, you need to install an Open Database Connectivity (ODBC) driver for Excel. You can then establish the connection, import the data, and refresh it as needed.
Before you can import data into a table in Excel, you must install an Open Database Connectivity (ODBC) driver. This is a piece of software that enables Excel to connect to the database and pull data out of it.
Microsoft doesn't provide ODBC drivers for Excel for Mac, so you need to get one from a third-party vendor. To find the latest list of compatible ODBC drivers, open your web browser, go to http://www.microsoft.com/mac/
, then search for ODBC Excel. At this writing, there are two providers:
http://www.openlinksw.com/
)http://www.actualtech.com/
)Each offers several different ODBC drivers for different types of database, so make sure you get the right one. Normally, you'll want to start by getting the trial version to make sure it does what you need, then pay for the full version. Some trial versions are limited by time; others are limited by the amount of data they'll return. Either way, you'll eventuallyneed to buy the full version.
To establish a connection to a database, position the active cell on the appropriate worksheet in the workbook you want to use, then choose Data
External Data Sources
Database
to open the dialog box for setting up the connection. Figure 10.5 shows the iODBC Data Source Chooser dialog box, which you use to establish a connection using OpenLink Software's ODBC driver.
Figure 10–5. Choose your database in the dialog box for the ODBC driver you installed. This screen shows the iODBC Data Source Chooser dialog box.
Use the controls in the dialog box to specify the connection to the data source. The specifics depend on the ODBC driver you're using.
When you have set up the connection, click the Return Data button. Excel displays the Returning External Data to Microsoft Excel dialog box (see Figure 10–6). In this dialog box, you can choose where to place the data that the connection returns:
Figure 10–6. In the Returning External Data to Microsoft Excel dialog box, choose whether to put the data on an existing worksheet, on a new worksheet, or in a PivotTable. You can click the Properties button to set the properties for the data returned from the database.
If you need to choose options for how Excel returns the data, click the Properties button in the Returning External Data to Microsoft Excel dialog box to display the External Data Range Properties dialog box (see Figure 10–7). Here you can choose the following options:
Figure 10–7. In the External Data Range Properties dialog box, name the connection, choose whether to save the query definition, decide when to refresh the data, and choose the layout to use.
NOTE: Some of the options in the External Data Range Properties dialog box are available only for certain types of connections.
When you've finished choosing options in the External Data Range Properties dialog box, click the OK button to close it and return to the Returning External Data to Microsoft Excel dialog box. Then click the OK button to close this dialog box. Excel brings in the data from the data source.
If you've set the table to update the data from the database automatically at intervals or when you open the workbook, Excel takes care of the refreshing. If you've set the table for manual refreshing, or if you need to pull the latest data into the table right this moment, you can refresh the table manually by using the commands on the Data
External Data Sources
Refresh
menu. Click the Refresh All command to refresh all the tables, or click the Refresh Data command to refresh just the data in the current table.
If a refresh seems to be taking too long, choose Data
External Data Sources
Refresh
Cancel Refresh
to cancel it.
If you need to pull data from a FileMaker Pro database into a table, choose Data
External Data Sources
FileMaker
to launch the FileMaker Pro Import Wizard. Follow through the steps of this Wizard as discussed in the section “Importing Data from a FileMaker Pro Database” in Chapter 1.
NOTE:To import data from a FileMaker Pro database, you must have FileMaker Pro installed on the Mac you're running Excel on.
When you've created a table, Excel normally resizes it for you automatically when you add or delete rows or columns. For example, when you add a record by using the Form dialog box, Excel expands the table to include it.
Excel also expands the table automatically if you add data to the row after the current last row in a table that doesn't have a Total row. Excel calls this feature Table AutoExpansion. If you don't want Excel to do this, click the AutoCorrect actions button that appears below and to the right of the first cell in the added row, then click Undo Table AutoExpansion (see Figure 10–8). Click the actions button again, then click Stop Automatically Expanding Tables.
NOTE: When you add a new row to a table using Table AutoExpansion, Excel makes the change only when you start typing data in the row. When you do, Excel applies the style to the row, and you can see that it's part of the table. But until you start typing, it's just another plain row.
Figure 10–8. You can use the AutoCorrect actions button both to undo Table AutoExpansion and to turn it off.
NOTE: To turn Table AutoExpansion back on, choose Excel
Preferences
or press Cmd+, (Cmd and the comma key). In the Excel Preferences dialog box, click the Tables icon in the Formulas and Lists area to display the Tables preferences pane. Select the Automatically Expand Tables As I Type check box, then click the OK button.
When you need to examine the data in your table, it's often useful to sort it. Excel lets you sort a table either quickly by a single field or by using multiple fields.
TIP:If you need to be able to return a table to its original order, include a column with sequential numbers in it. These numbers may be part of your records (for example, sequential sales numbers for transactions) or simply ID numbers for the records. In either case, you can use AutoFill to enter them quickly. To return the table to its original order, you can then sort it by this column.
To sort a table by a single field, click any cell in the column you want to sort by, then choose Data
Sort & Filter
Sort
, clicking the main part of the Sort button. This produces a sort in ascending order (A to Z, low values to high values, early dates to later dates, and so on). To reverse the sort to descending order, click the main part of the Sort button again.
NOTE: You can also sort by choosing Data
Sort & Filter
Sort
Ascending
, Data
Sort & Filter
Sort
Descending
, or by one of the other items on the Sort pop-up menu: Cell Color on Top, Font Color on Top, or Icon on Top. Usually, ascending and descending are the most useful kinds of sorting for a table. (You normally use sorting by Cell Color on Top, Font Color on Top, or Icon on Top for sorting cells that have conditional formatting applied.)
After you sort, the table remains sorted that way until you change it.
Often, it's useful to sort your table by two or more fields at the same time. For example, in a customer database, you may need to sort your customers first by state and then by city within the state.
To sort by multiple fields, follow these steps:
Data
Sort & Filter
Sort
Custom Sort
to display the Sort dialog box. Figure 10–9 shows the Sort dialog box with two criteria entered and a third criterion under way.
Figure 10–9. In the Sort dialog box, you can set up exactly the sort criteria you need to identify data in your database.
Figure 10–10. Select the Case sensitive check box in the Sort Options dialog box if you want to treat lowercase letters differently than their uppercase versions.
NOTE: When you're sorting data that's not in a table, there are two main differences. First, the My Data Has Headers check box in the Sort dialog box is available, and you must select it if the data range you're sorting includes a header row. (Otherwise, Excel sorts the headers into the data range.) Second, you can select the Sort left to right option button in the Sort Options dialog box to sort columns rather than rows, a choice that's not available in a data table.
When you've created a large table, you may need to check it for duplicate records and remove those you find. Excel provides a Remove Duplicates feature that saves you having to comb the records by hand.
CAUTION: Two warnings before removing duplicate values: First, make sure you have a backup copy of your database workbook—for example, use Finder to copy the current version of a file to a safe location. Second, be certain you know which fields in the table should contain unique values and which can contain duplicate values. For example, a customer ID number field must be unique, because each customer has a different ID number; but a customer last name field can't reasonably be unique, because many customers will likely share last names. Most databases need a unique ID number or code of this type.
To remove duplicate records from a table, follow these steps:
Tables
Tools
Remove Duplicates
from the Ribbon or Data
Table Tools
Remove Duplicates
from the menu bar to display the window shown in Figure 10–11.Figure 10–11. Use this window to locate duplicate values in columns that should contain only unique values. The window's title bar shows the name of the data table.
TIP: Normally, it's best to check a single column at a time for duplicate values. Make sure that the column is one that must contain a unique value.
When you need to find records in a table that match the terms you specify, you can filter it. Filtering makes Excel display only the records that match your search terms, hiding all the other records.
NOTE: You can also search for records by using Excel's Find feature. Choose Edit
Find
from the menu bar or press Cmd+F to display the Find dialog box, type your search term in the Find What box, then click the Find Next button. Filtering displays all the matching records together rather than spread out in the table, so it's often more convenient than using Find.
To make filtering easy, Excel provides a feature named AutoFilter. To use AutoFilter, follow these steps:
Figure 10–12. To apply filtering, click the pop-up arrow on a column heading to display the AutoFilter window (left). In the Filter area, open the first pop-up menu, and choose the comparison you want (right). You can then add further comparisons as needed.
NOTE: The filter comparisons depend on the contents of the column you selected in the table. For example, if the column contains numbers, the comparisons include the mathematical comparisons Greater Than, Greater Than or Equal To, Less Than, Less Than or Equal To, Between, Top 10, Bottom 10, Above Average, and Below Average. If the column contains dates, the comparisons include Before, After, Between, Tomorrow, Next Week, Next Month, and Next Year.
When you've specified the details of the filter, Excel applies it to the table and reduces the display to those rows that match the filter. Excel displays a filter symbol in place of the drop-down button on the column that contains the filtering (as on the State column heading in Figure 10–13).
Figure 10–13. The filter symbol (shown on the State column heading here) indicates that you're filtering the table by that column.
To remove filtering from a single column, click the filter symbol on the column heading, then click the Clear Filter button in the AutoFilter window.
To remove filtering from the table as a whole, choose Data
Sort & Filter
Filter
, deselecting the Filter button in the Sort &Filter group.
3.145.166.149