Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Formatting Subtotal Rows.

Formatting Subtotal Rows

Written by Allen Wyatt (last updated September 4, 2021)
This tip applies to Excel 97, 2000, 2002, and 2003


When you add subtotals to a worksheet, Excel automatically formats the subtotals using a bold font. You, however, may want to have some different type of formatting for the subtotals, such as shading them in yellow or a different color.

If you use subtotals sparingly and only want to apply a different format for one or two worksheets, you can follow these general steps:

  1. Apply your subtotals, as desired.
  2. Select the entire data table, including the subtotals.
  3. Using the Outline area at the left of the screen, collapse the detail in your worksheet so that only the subtotals are showing.
  4. Press F5 to display the Go To dialog box. (See Figure 1.)
  5. Figure 1. The Go To dialog box.

  6. Click Special to display the Go To Special dialog box. (See Figure 2.)
  7. Figure 2. The Go To Special dialog box.

  8. Select the Visible Cells Only option button.
  9. Click OK. Now, only the visible subtotal rows are selected.
  10. Apply your formatting, as desired.

If you will be repeatedly adding and removing subtotals to the same data table, you may be interested in using conditional formatting to apply the desired subtotal formatting. Follow these steps:

  1. Before applying your subtotals, select your entire data table.
  2. Choose Conditional Formatting from the Formatting menu. Excel displays the Conditional Formatting dialog box.
  3. In the left-most drop-down list, choose Formula Is. The dialog box changes to reflect your choice. (See Figure 3.)
  4. Figure 3. The Conditional Formatting dialog box.

  5. In the formula box, just to the right of the drop-down list used in step 3, enter the following formula: =ISNUMBER(FIND("Grand Total",$A1))
  6. Click Format to display the Format Cells dialog box.
  7. Using the controls in the dialog box, set the formatting as you want it applied to the Grand Total row.
  8. Click OK to dismiss the Format Cells dialog box.
  9. Click Add. Excel adds a second conditional format.
  10. In the left-most drop-down list of the second condition, choose Formula Is. The dialog box changes to reflect your choice.
  11. In the formula box, just to the right of the drop-down list used in step 9, enter the following formula: =ISNUMBER(FIND("Total",$A1))
  12. Click Format to display the Format Cells dialog box. (See Figure 4.)
  13. Figure 4. The Format Cells dialog box.

  14. Using the controls in the dialog box, set the formatting as you want it applied to the Total row.
  15. Click OK to dismiss the Format Cells dialog box.
  16. Click OK to dismiss the Conditional Formatting dialog box.

When following the above steps, make sure that you replace A1 (steps 4 and 10) with the column in which your subtotals are added. Thus, if your subtotals are in column G, you would use G1 instead of A1.

If you need to do formatting of subtotals on quite a few worksheets, then you may want to create a macro that will do the formatting for you. The following macro examines all the cells in a selected range, and then applies cell coloring, as appropriate.

Sub FormatTotalRows()
    Dim rCell as Range

    For Each rCell In Selection
        If Right(rCell.Value, 5) = "Total" Then
            Rows(rCell.Row).Interior.ColorIndex = 36
        End If

        If Right(rCell.Value, 11) = "Grand Total" Then
            Rows(rCell.Row).Interior.ColorIndex = 44
        End If
    Next
End Sub

The macro colors the subtotal rows yellow and the grand total row orange. The macro, although simple in nature, is not as efficient as it could be since every cell in the selected range is inspected. Nevertheless, on a 10 column 5000 row worksheet this macro runs in under 5 seconds.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2984) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Formatting Subtotal Rows.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Creating a New Document in VBA

When working with documents in a macro, it makes sense that you may need to create a document from time to time. Here's ...

Discover More

Accessing Dependent and Precedent Information

The auditing tools provided in Excel can provide some very helpful information about how your formulas and data are ...

Discover More

Positioning Line Numbers

Line numbers can be added to a document, and is typically done in legal documents. The line numbers appear to the left of ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (menu)

Subtotals Option Grayed Out

The Subtotals option on the Data menu is normally available for adding or removing subtotals to data tables. If the ...

Discover More

Problems with Nested Subtotals

If you have a worksheet that has nested subtotals, you may have run across a problem where the subtotals and grand total ...

Discover More

Moving Subtotals

When you add subtotals to a worksheet, Excel typically places them in the same column that you are subtotaling. If you ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two less than 3?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.