Chapter 9: Tables and Worksheet Databases: Figure 9-13: This Table Shows Sales by Month and by Region
Chapter 9: Tables and Worksheet Databases: Figure 9-13: This Table Shows Sales by Month and by Region
To change the name of a table, select any cell in the table, use the Table Name box in
the Table Tools➜Design➜Properties group. Or, you can use the Name Manager to
change the name of a table (Formulas➜Defined Names➜Name Manager).
Most of the time, your formulas will refer to a specific column in the table, rather than the entire
table. The following formula returns the sum of the data in the Sales column:
=SUM(Table2[Sales])
Notice that the column name is enclosed in square brackets. Again, the formula adjusts automati-
cally if you change the text in the column heading.
Keep in mind that the preceding formula does not adjust if table rows are hidden as a
result of filtering. SUBTOTAL and AGGREGATE are the only functions that change their
result to ignore hidden rows. To ignore filtered rows, use either of the following formulas:
=SUBTOTAL(109,Table2[Sales])
=AGGREGATE(9,1,Table2[Sales])
Even better, Excel provides some helpful assistance when you create a formula that refers to
data within a table. Figure 9-14 shows the Formula AutoComplete feature helping create a for-
mula by showing a list of the elements in the table.
Here’s another example that returns the sum of the January sales:
=SUMIF(Table2[Month],”Jan”,Table2[Sales])
Figure 9-14: The Formula AutoComplete feature is useful when creating a formula that refers to data in a
table.
Using this structured table syntax is optional — you can use actual range references if you like.
For example, the following formula returns the same result as the preceding one:
=SUMIF(B3:B8,”Jan”,D3:D8)
To refer to a cell in the Total row of a table, use a formula like this:
=Table2[[#Totals],[Sales]]
If the Total row in Table2 is not displayed, the preceding formula returns a #REF error.
This formula returns the value in the Total row of the Sales column in Table2.
To count the total number of rows in Table2, use the following formula:
=ROWS(Table2[#All])
The preceding formula counts all rows, including the Header row and Total row. To count only
the data rows, use a formula like this:
=ROWS(Table2[#Data])
A formula that’s in the same row as a table can use a #This Row reference to refer to table data
that’s in the same row. For example, assume the following formula is in row 3, in a column out-
side Table2. The formula counts the number of entries in row 3 of Table2:
=COUNTA(Table2[@])
You can also combine row and column references by nesting brackets and including multiple ref-
erences separated by commas. The following example returns Sales from the current row divided
by the total sales:
=Table2[[@],[Sales]]/Table2[[#Totals],[Sales]]
A formula like the preceding one is much easier to create if you use the pointing method.
Table 9-1 summarizes the row identifiers for table references and also describes which ranges
they represent.
You can use the SUBTOTAL function to generate consecutive numbers for nonhidden
rows in a filtered table. The numbering will adjust as you apply filtering to hide or dis-
play rows. If your table has the field names in row 1, enter this formula in cell A2 and
then copy it down for each row in your table:
=SUBTOTAL(3,B$2:B2)
When you have a small range, you can type the missing cell values manually. If your worksheet
database has hundreds of rows, though, you need a better way of filling in those cell values.
Here’s how:
1. Select the range (A3:A14 in this example).
2. Choose Home➜Editing➜Find & Select➜Go To Special to display the Go To Special
dialog box.
3. In the Go To Special dialog box, select the Blanks option.
4. Click OK to close the Go To Special dialog box.
5. In the Formula bar, type =, followed by the address of the first cell with an entry in the col-
umn (=A3 in this example), and then press Ctrl+Enter to copy that formula to all selected
cells.
6. Press Esc to cancel the selection.
7. Reselect the range and then choose Home➜Clipboard➜Paste Values.
Each blank cell in the column is filled with data from above.
You can use advanced filtering with a worksheet database or with a table.
The examples in this section use a real estate listing worksheet database (shown in Figure 9-15),
which has 125 records and 10 fields. This database contains an assortment of data types: values,
text strings, logical, and dates. The database occupies the range A8:H133. (Rows above the table
are used for the criteria range.)
Figure 9-15: This real estate listing database is used to demonstrate advanced filtering.
h It must consist of at least two rows, and the first row must contain some or all field
names from the table. An exception to this is when you use computed criteria. Computed
criteria can use an empty Header row. (See the “Specifying computed criteria” section,
later in this chapter.)
h The other rows of the criteria range must consist of your filtering criteria.