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

Formatting Subtotal Rows

by Allen Wyatt
(last updated July 3, 2018)

6

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. Make sure the Home tab of the ribbon is displayed.
  3. Click the Conditional Formatting tool. Excel displays a series of choices.
  4. Click Manage Rules. Excel displays the Conditional Formatting Rules Manager dialog box.
  5. Click New Rule. Excel displays the New Formatting Rule dialog box.
  6. In the Select a Rule Type area at the top of the dialog box, choose Use a Formula to Determine Which Cells to Format. (See Figure 3.)
  7. Figure 3. The New Formatting Rule dialog box.

  8. In the formula space, enter the following formula: =ISNUMBER(FIND("Grand Total",$A1))
  9. Click Format to display the Format Cells dialog box.
  10. Using the controls in the dialog box, set the formatting as you want it applied to the Grand Total row.
  11. Click OK to dismiss the Format Cells dialog box.
  12. Click OK to dismiss the New Formatting Rule dialog box. The rule you just created now appears in the Conditional Formatting Rules Manager dialog box.
  13. Click New Rule. Excel again displays the New Formatting Rule dialog box.
  14. In the Select a Rule Type area at the top of the dialog box, choose Use a Formula to Determine Which Cells to Format.
  15. In the formula box, enter the following formula: =ISNUMBER(FIND("Total",$A1))
  16. Click Format to display the Format Cells dialog box. (See Figure 4.)
  17. Figure 4. The Format Cells dialog box.

  18. Using the controls in the dialog box, set the formatting as you want it applied to the Total row.
  19. Click OK to dismiss the Format Cells dialog box.
  20. Click OK to dismiss the New Formatting Rule dialog box.
  21. Click the up and down arrows to move the rules you created to the order in which they should be evaluated.
  22. Click OK to dismiss the Conditional Formatting Rules Manager dialog box.

When following the above steps, make sure that you replace A1 (steps 7 and 14) 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 format 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 a darker shade of yellow. (The exact colors on your system may vary depending on the theme you have loaded.) 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 (8110) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel 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 Hyperlinks from E-mail Addresses

Got a document that has a whole raft of e-mail address in it? You can easily convert all of them to clickable hyperlinks ...

Discover More

Replacing Spaces in Part Numbers with Dashes

Word has a power capability to search for information and then replace that information in some way. Finding the right ...

Discover More

Renaming a Folder

Folders are a great organizational tool in Drive. Once you name a folder, you aren't stuck with that name. You can change ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Adjusting Row Height for a Number of Worksheets

Adjusting the height of a row or range of rows is relatively easy in Excel. How do you adjust the height of those same ...

Discover More

Adjusting Row Height when Wrapping Text

If you have some cells merged in a worksheet, and you wrap text within that merged cell, Excel won't automatically resize ...

Discover More

Hiding and Unhiding Rows

When building a worksheet, you may need to hide some of the rows or unhide other, previously hidden, rows. It's easy to ...

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}] 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 5 + 2?

2013-10-29 09:26:35

awyatt

Mike: It means that you are declaring the variable rCell (a variable name) to contain a range reference.

-Allen


2013-10-29 08:13:08

Mike


What does this mean?


Dim rCell as Range;


2013-10-28 12:17:38

Paul

Why would a person need/want to use the "isnumber"? I tried the formatting using just the "Find" part of the formula and it worked just fine.


2013-10-28 03:54:24

Rudra Sharma

@ Jerry
Thanks Jerry for your veryuseful shortcut key combination.

With Regards
Rudra


2013-10-26 10:40:31

Jerry

A handy keyboard shortcut for selecting visible cells only (steps 4-6 of the first procedure above) is Alt+; (semi-colon). I have found this useful when I need to copy just the subtotals from a subtotaled list onto another sheet.


2013-10-26 10:05:11

Joe

Why not use Styles? These are flexible based on subtotal level and can apply across the workbook.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu 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.