I tried to use the { =SUM(ABOVE) } formula in a table but the answer was obviously incorrect
Article contributed by Suzanne S. Barnhill
If you have numbers in a table column and use the Table | Formula command in Word 2003 or earlier (Table Tools | Layout | Data | Formula in Word 2007), Word by default inserts the { =SUM(ABOVE) } formula field. This is quite often what you want: to sum the numbers in the column above the current cell. But often the result is obviously erroneous. There are two possible reasons for this:
- If you are using Word 97 or earlier, the { =SUM(ABOVE) } field does not work for more than 85 rows. (This is not a problem with { =SUM(LEFT) } because the number of columns is limited to 63 anyway.)
- A much more common problem, in all Word versions, is that Word stops counting when it gets to an empty cell or one with text in it instead of a number.
To get around either of these problems, however, you can use the { =SUM( ) } field with cell addresses. For example, to add the numeric contents of the cells in column D (let's say there are 90 rows; the first one is a Heading Row, and #90 is the one where you want to put the answer), disregarding empty and nonnumeric cells, you can use the formula { =SUM(D2:D89) }.
But what if you don't know how many rows you have? Unlike WordPerfect, Word does not display cell references in the status bar. Despite many requests for this feature, it will likely never be provided: Word’s developers tell us that merged cells and nested tables make the calculation so processor-intensive that constantly updating the status bar would adversely affect Word’s performance.
There is, however, a way to get the address of a specific cell upon request. To help Word 97 users, Microsoft provided the TableCellHelper macro in the Macros8.dot template in the Macros folder of C:\Program Files\Microsoft Office\Office\. Although some subsequent Word versions have included templates containing macros, none of these has contained this macro. You can, however, download the Macros8.dot template by following this link. This macro still works in all versions, including Word 2007.
When you run this macro, a message box reports the address of the cell you're in and the total number of rows and columns in the table.
The easiest way to make this macro available in every document you create is to copy it into the Normal template, as follows:
-
Word 2003 and earlier: With the Macros8.dot template open, go to the Tools | Templates and Add-ins dialog, click Organizer… and select the Macro Project Items tab. You'll see two boxes labeled “Macro projects available in.” The one on the right will say “Normal.dot (global template).” The one on the left will say “Macros8.dot (Template).” When you select the TableCellHelper macro in the list on the left, the Copy button arrow will point right, and the labels above the boxes will say “In Macros8.dot” and “To Normal.dot.” Click the Copy button, and you will have added the TableCellHelper macro to the Normal template. There is another macro called TableCellHelper.AddToStd which, when run, will place a TableCellHelper button on the Standard toolbar. Since this button, as inserted, is entirely blank, so you can't even see where it went, I don't recommend copying this macro.
-
Word 2007: On the View tab, locate the Macros group, click on the Macros button, and choose View Macros. Click on Organizer… This opens an Organizer dialog similar to the one in Word 2003 and earlier; from here you can follow the instructions (above) for those versions.
As an alternative to copying the macro to your Normal template, you could create a new template and store it in Word's Startup directory (as defined in Tools | Options | File Locations). Storing it there makes it an add-in (or global template). You can then copy the macros to your add-in.
If you need to use the TableCellHelper macro very often, you'll want some easier way to do it than by opening the Macros dialog, selecting TableCellHelper, and clicking Run. So you may want to add it to the Table menu or a toolbar in Word 2003 or earlier or to the QAT in Word 2007. Do this as follows:
-
Word 2003 and earlier: Open Tools | Customize. On the Commands tab, scroll down the list of Categories till you see Macros. Find the TableCellHelper macro (if you copied the TableCellHelper.AddtoStd macro, be careful not to select this one). Select the TableCellHelper macro item and drag it to the menu bar, hovering over the Table menu item. When the Table menu opens, drop the macro in the desired location on the menu. If you prefer to have a toolbar button for this macro, drag it to a toolbar instead.
Note: When you add a macro to a menu or toolbar, by default it will display the long string of text that is displayed in the Customize dialog (and no icon). This is rarely what you want.
-
For a menu item, you can modify the text to be anything you like. To do this, right-click on the menu item and change the text in the Name box.
-
For a toolbar button, you will probably want an icon instead; right-click on the button, choose Change Button Image, and select one of the icons offered (I used the big yellow question mark). Then right-click again and choose Default Style. Note that the “default style” for a toolbar button is an image only; for a menu item it is an image and text.
-
The menu of actions you can use to modify a menu item or toolbar button (which can also be accessed by selecting the menu item or toolbar button and clicking Modify Selection in the Customize dialog) also includes Copy Button Image (to copy the icon from another button), Paste Button Image (to paste it on your new button), and Edit Button Image, which allows you to create your own custom button icon. (For more on adding buttons to menus and toolbars, see “How to assign a Word command or macro to a toolbar or menu.” For a library of button images, see “Assigning custom button faces to your toolbar and menu buttons.”
-
Word 2007: Right-click on the QAT choose Customize Quick Access Toolbar… In the Word Options | Customize dialog, choose Macros under “Choose commands from:” and select the TableCellHelper macro. Click Add>> to add it to the QAT. While it is still selected, click Modify… and choose a button image for the new button (good luck with finding an appropriate one!).
Word MVP Greg Maxey offers an improved version of the TableCellHelper macro at his Web site.
For another workaround, see the following article: “How to get a formula field to total an entire table column, even if some cells in the column contain text or are blank.”