In this chapter
Defining Suitable Data for Excel Tables 132
Adding a Total Row to a Table 137
Adding New Formulas to Tables 139
Selecting Only the Data in the Column 142
Using Table Data for Charts to Ensure Stickiness 145
Replacing Named Ranges with Table References 146
Creating Banded Rows and Columns with Table Styles 149
Dealing with the AutoFilter Drop-Downs 152
A fundamental use of Excel is for analyzing two-dimensional tables of data. Most worksheets contain headings at the top and then rows of data. Most Excel customers spend a lot of time working with tables of data. Microsoft recognized this and added intelligent tables to Excel 2007. If you explicitly tell Excel 2007 that you are working on a table of data, it displays a custom Table ribbon that has a number of amazing features.
Some of the benefits of Excel’s intelligent tables include the following:
Many Excel spreadsheets contain data that is not suitable for Excel tables. For the purpose of this chapter, a table is a range of Excel data. Each row in the range is one record of data. Each row might describe, for example, an invoice or a customer or an inventory item. Each column in the table creates another field for each row. Fields might include invoice number, customer name, total sales, and so on. A table usually has headings in the first row.
The simple range in Figure 8.1 would make a suitable table because each row in this range is a record, and each column is a field.
There are four ways to create a table in Excel 2007:
When you use any of these methods, Excel uses IntelliSense to determine the edge of the table. Excel looks for a completely blank row and a completely blank column to define the edges of the table.
Excel shows the suspected table range in the Create Table dialog, as shown in Figure 8.2. You need to verify that this range is correct. If your table has headers, you leave the My Table Has Headers check box checked and press OK.
As shown in Figure 8.3, Excel adds a default table format to your range. The headings gain autofilter drop-downs. A new ribbon called Table Tools—Design is displayed. Excel assigns a name similar to Table1
to the table. Don’t worry; if any of this is annoying to you, you can turn off many of the features with a click of the mouse.
Notice that in Figure 8.3, the headings appear in Row 2 of the worksheet. As you scroll down through the table, you can eventually scroll to the point where Row 2 is no longer visible in the window. At this point, Excel moves the headings from Row 2 and shows them where column names A, B, C, D normally display. Figure 8.4 shows the headings as column names.
These heading names stay as column names as long as all these are true:
Once any of the above conditions is no longer true, the headings disappear from the column name area.
Excel 2007’s automatic heading visibility feature is very cool. With earlier versions of Excel, many did not know there was a way to freeze panes. Whether you knew about that feature or not, it is a positive feature 90% of the time, though it’s not perfect.
One problem with Excel 2007’s automatic heading visibility feature is that the autofilter drop-downs disappear from the headings when they are scrolled up to the column names.
Second, it is a bit annoying that the headings disappear when you select a cell outside the table. I think that if I can see part of a table in the window, Excel should keep the headings up as part of the column names. The cell pointer can be a distraction in a dataset, and if, for example, you are showing your manager something on the screen, you might have a tendency to click outside the table so that the manager does not think you are trying to show him one particular cell.
Third, the automatic heading visibility feature does not work for the first column. In Figure 8.5, for example, a wide table has labels in Column A. After you choose First Column, Excel properly formats Column A. However, if you scroll over to see the month of December, Excel does not make the Column A values stay visible.
The old-style Freeze Panes command is still available and is even a bit easier to use in Excel 2007.
In prior versions of Excel, you were forced to put the cell pointer in the first cell that should not be frozen before invoking the Freeze Panes command. In Excel 2007, Microsoft has added two new commands that allow you to freeze the first row or the first column from anywhere. Here’s how you freeze the first row:
You can now scroll anywhere on the worksheet and always see the first row.
It is annoying, but the Freeze First Column resets the Freeze First Row icon, and vice versa. If you need to freeze both the first column and first row, you will have to use the Freeze Panes command as described in the following sections.
To turn off the Freeze Panes option, you again select the Freeze Panes icon in the View ribbon. The first option in the drop-down is now Unfreeze Panes. You can select this option to unlock the view; you can then scroll anywhere in the window.
There may be times when you want several rows or columns to remain visible. Just as in previous versions of Excel, you can do this when you understand how Freeze Panes works.
Consider the worksheet in Figure 8.7. You would always want to see the data in Columns A:D at the left side of the window. There are several rows of title information that don’t necessarily need to be visible at the top of the worksheet as you scroll, but it would be good to see Rows 5 and 6 at the top of the window as you scroll.
You can set up the headings to stay visible by following these steps:
The result is that you can scroll down and right. Even out at Column V, Row 62, you can see the headings in Rows 5:6 and the values in Columns A:D, as shown in Figure 8.9.
The key to using the Freeze Panes command is that you must place the cell pointer before using the command. The command freezes everything that was above and to the left of the cell pointer location when the command was invoked.
To freeze only Columns A:B and no rows, you would invoke the command from Row 1 of Column C. Because there is nothing above the cell pointer, no rows are frozen.
There is a Totals Row checkbox in the Table Styles Options group of the Table Tools Design ribbon. When you select this box, Excel automatically adds a total to the bottom of your table.
By default, Excel adds the word Total to the first column of the table and adds a formula to the right-most column of the table to sum the column.
Figure 8.10 shows the default total row for a table. To add a sum formula to Column C, you select the cell for Column C in the total row. When a drop-down arrow appears, you select Sum from the list.
In Figure 8.10, instead of using the SUM
formula, Excel uses the SUBTOTAL
function, with a first argument of 109
. The SUBTOTAL
function is similar to the SUM
function, with two exceptions. First, the function ignores other SUBTOTAL
functions in the range. Second, with a first argument in the 101–109 range, Excel ignores any values that are hidden, including rows that are hidden by the autofilter drop-downs.
The total cost in Figure 8.10 is $1.4 million. In Figure 8.11, the Region column is filtered to only the Central region. Because the SUBTOTAL
function ignores hidden rows, the total cost automatically updates to show $448,511.
SUBTOTALS
function reflects the total of the visible rows.When you use tables, you can toggle the total row on and off. You use the Total Row check box in the Table Tools Design ribbon to turn on or off the totals. In most cases, Excel remembers when you have customized the totals to provide totals for the last two columns. However, you might find that if you add new columns to a table, you will have to add these totals to the new columns using the dropdown in the total row.
A common feature of tables is that they tend to grow and expand. Every day, you might add new records to a table or paste new records to the bottom of a table. Or, you might add a new column with a new calculation.
Excel can automatically expand a table, or you can choose to expand a table manually. When you expand a table, any references to the table automatically expand.
The easiest way to add rows to a table is from the last row of the table. If you are in the last column of the last row and press the Tab key, Excel adds a new row to the table and moves the cell pointer to the first column in the new row. This behavior is similar to existing functionality in tables in Microsoft Word.
However, the simplest way to add a new row to a table is to click in the blank row under the table and type new data. As soon as you enter something in a cell just below the table, Excel expands the table formatting to include the new row. Excel also displays an AutoCorrect lightning bolt icon. If you don’t want Excel to automatically expand the table, you can use the drop-down next to this icon to undo the table AutoExpansion, as shown in Figure 8.12.
The bottom-right cell of a table contains a small angle-bracket in the lower-right corner of the cell. You can use this angle-bracket to manually extend the table.
When you click the angle-bracket, you can either drag down to add more rows or drag right to add more columns to the table.
You can also select Table Tools, Design, Properties, Resize Table. The Resize Table dialog appears, allowing you to specify the new range for the table. There are a few limitations. For example, you cannot change the header row during this process.
To add a new column to a table, you go to the blank cell to the right of the last header and type a new header for the column. Excel automatically extends the table by another column and copies any table formatting to the new column. The AutoCorrect lightning bolt icon appears. If you don’t want the new column to be part of the table, you use the drop-down next to the AutoCorrect icon to undo the table AutoExpansion.
Way back in Excel 97, Microsoft added something called Natural Language Formulas to Excel. With Excel 2007, those old formulas are officially depreciated. However, the new-style table formulas are reminiscent of those formulas.
In Figure 8.13, a new column has been added to the table, with the heading Profit. To add a formula to that column, you follow these steps.
=[Revenue]
, as shown in Figure 8.13.
=[Revenue]-[Cost]
, as shown in Figure 8.14.
=[Revenue]-[Cost]
is easier to understand than D3–C3.In prior versions of Excel, after adding a formula to a new column, you had to double-click the fill handle to copy the formula down to all rows of the table. This new functionality will save you time.
If you don’t want to have the formula copied down to all rows, you can undo the behavior by selecting the AutoCorrect icon and then choosing the appropriate option.
You might at some point have a column in a table and not want Excel to use the same formula everywhere in the column. Excel 2007 calls this a calculated column exception. Because any formula that you enter in the column is automatically copied to the entire column, you need to use special care to set up a calculated column exception.
Say that you already have a formula in a column and want to change to a different formula in just one cell. In this case, you follow these steps:
Excel marks this cell with a green triangle. If you hover your mouse over the green triangle, Excel tells you, “This cell is inconsistent with the column formula.”
Tip From
When you set up a single-cell column exception, Excel stops automatically copying formulas in that column.
There are other ways to set up a first column exception:
The automatic copying of formulas includes one minor annoyance. In prior versions of Excel, you would add a new column by following these steps:
Now that Excel is, in essence, performing the last step for you, there is no chance to format the first cell before it gets copied. In Figure 8.16, the calculation for gross profit percentage was copied before the cell could be formatted as a percentage.
You can try formatting Cell F3 before entering the formula, but the table logic appears to overwrite this format when the formula is copied to the column. Thus, you have two options:
There are several new options you can use when selecting data in a table. If you are going to format a table, you probably just want to format the numbers in the table and not the headings. Excel has added distinct methods for selecting the data portion of a column or selecting the entire table column with headings and totals.
One way to select the data in a column is to right-click on a cell in the table. From the context menu, you choose the Select option. The flyout menu offers three choices, as shown in Figure 8.17:
You can also use the old Excel shortcuts to select rows or columns. These shortcut keys are modified when you are in a table:
Excel has added a new arrow mouse pointer that you can use in selecting table rows and table columns. The use of this mouse pointer is a bit tricky. The following figures show some examples:
If you are a heavy-duty user of Excel, you will likely find yourself using these new table selection methods. The new conditional formatting options such as data bars and color scales require you to select the data in a column without the total row. Mastering the various selection methods will greatly enhance your ability to work with the new formatting.
When you define a range as a table and expand the table, any references to the table also expand. If you routinely have to re-create new charts every month when you receive new data, you will love this feature.
Before creating a chart, you make a table out of the underlying data. In Figure 8.24, for example, the chart is based on the table in A1:D4. Currently, the chart has three months’ worth of data.
If you type a heading for the new month in Cell E1, immediately, the chart redraws to include data for April. You fill in the data for the new month, and you will not have to ever re-create a chart; the new data is added to the chart, preserving the old formatting, as shown in Figure 8.25.
A benefit of using tables is that Excel understands a new reference style for formulas that point to data in a table. A new name is created automatically when a table is defined. The name includes the name of the table (something like Table1
) and the name of the column.
The biggest benefit of this new referencing style is that the ranges that the names refer to are expanded automatically when the table expands. This new referencing style will eliminate many of the chances for error that existed with using named ranges.
When a table is defined, it becomes easier to reference the table from outside the table. Figure 8.26 shows a sales rep lookup table. Because this is the first table in the workbook, Excel has assigned the name Table1
to this table.
Table1
.Figure 8.27 shows an invoice register located on another sheet in the workbook. Like many mainframe reports, this one includes the sales rep number, without the name and region information. To add a VLOOKUP function to Figure 8.27 that references Table1, follow these steps:
VLOOKUP
formula in Column D. When you get to the second argument, type the letter T, and the AutoComplete list scrolls down to the T entries. Among the function names are entries for Table1
and Table2
, as shown in Figure 8.27.
Table1
nomenclature.=VLOOKUP($B2,Table1,COLUMN(B2),False)
.Table1
, the references here to Table1
expand as well.Table1
automatically recalculate to include the new rows.To reference an entire column from outside a table, you use the syntax TableName
[
ColumnName
]
. When you do this, Excel’s AutoComplete feature provides a list of column names for you. After you type Table1[
, the AutoComplete list shows all the columns in the table, plus additional keywords (which are discussed in the following section, “Using Structured References to Refer to Tables in Formulas”). The AutoComplete list is shown in Figure 8.29.
References to a table column do not include the header or total row. While this behavior is usually desired, there might be instances when you use a INDEX or OFFSET function that you expect Excel to include the heading as row 1 in the function.
The formula in Figure 8.30 uses three references to a table to find the sales for a particular product and a particular region. The nomenclature Quantity, Product, and Region is easier to understand than cell addresses such as D2:D87. This is the complete formula in Cell G3:
=SUMIFS(Table1[Quantity],Table1[Product],$F3,Table1[Region],G$2)
Table references are valid on any worksheet in the workbook. If you want to refer to a table that is seven worksheets away, you can still use the Table1
nomenclature, without prefixing the worksheet name.
Microsoft has created a fairly comprehensive way to refer to various parts of tables. You’ve seen some of the table nomenclature syntax in the previous two sections. The following are complete details for writing formulas that refer to tables:
TableName
[
Qualifier
]
or TableName
[[
Qualifier
]]
.TableName
[[
Qualifier1
],[
Qualifier2
],
Qualifier3
]]
.Column1
, Column2
, and so on.#All
, #Data
, #Headers
, #Totals
, #ThisRow
.#ThisRow
qualifier must be used in conjunction with another qualifier.This system allows you to select a wide variety of references without having to use cell references. To get the total of sales from Table1
, you can either use =SUM(Table1[Sales])
or =Table1[[#Total],[Sales]]
. The second syntax returns a #REF!
error if someone turns off the Totals Row check box in the Table Tools Design ribbon.
Figure 8.31 shows various structured references.
In previous versions of Excel, creating banded rows or columns required creative conditional formatting or tedious manual work. Creating banded rows or columns in a table is relatively simple in Excel 2007.
The fourth group on the Table Tools Design ribbon is Table Style Options. This group includes check boxes for Banded Rows and Banded Columns. These check boxes work only if the selected table style includes rules for banded columns and/or banded rows. If you have selected the plain white table style, turning on or off banded rows and columns will have no effect.
Figure 8.32 shows five tables. The first table contains banded rows. The second table has banded columns. The third table leaves banded rows and columns off, but the first column, last column, header row, and total row are checked. The top table in Column H contains both banded rows and banded columns. The last table contains a custom format to change the banding from one stripe to two stripes. The next section provides details on how to customize the table style.
At the bottom of the Table Styles gallery, there is a New Table Style button. I would encourage you not to use this button! It can be rather intimidating to set up a completely new style. It is often easier to start with an existing style and modify it. To do this, you right-click a style and choose Duplicate, as shown in Figure 8.33.
After you choose Duplicate, Excel displays the Modify Table Quick Style dialog box. Excel assigns a new name to the style, adding a 2 to the existing style name. You can rename the style if you like.
To create double-height banded rows, you follow these steps:
You might find some of the table behavior annoying. If you want banded columns but don’t want to use a full-fledged table, you can temporarily create a table, apply a banded row format to the table, and then convert it back to a range in order to have a banded row format on the range. Here’s how you do it:
A common spreadsheet style rule says that you should right-justify the headings above numeric columns. If you regularly follow this convention, you will certainly be annoyed with the default choice that all tables are automatically created with the autofilter drop-downs applied.
In Figure 8.35, the first range contains data with the Q1 headings in the first row. If you apply a table to a range, the autofilter drop-downs completely cover the headings, making the table useless. The table in Rows 10:16 shows this.
One option, shown in Row 19, is to begin centering your headings instead of right-justifying them.
The final option, shown in Row 27, is to keep the table but turn off the autofilter for the table. Frustratingly, this option does not appear on the Table Tools Design ribbon. Instead, you need to go to Home, Editing, Sort & Filter, Filter to toggle away the drop-downs.
There are more tricks available for tables. See Chapter 13, “Removing Duplicates and Filtering,” and Chapter 14, “Sorting,” for more table tricks.
18.222.22.9