Overcome a Nuance of Excel's Subtotal Feature

Share this content

By David Ringstrom, CPA

Many users rely on the Subtotal feature in Excel to instantly insert totals, averages, counts, or other statistics into a list. As you'll see, the feature is easy to use – until you want to copy or format just the total rows. In this article, I'll explain the nuance so that you'll be in complete control of this feature.
Figure 1 shows a typical data set for use with the Subtotal feature. We can use the Subtotal feature to insert a total after each product as well as a grand total at the bottom. As an added benefit, we'll then be able to expand and collapse our list by way of outlining buttons that will appear at the left. To do so:
  1. Select any cell within your list.
  2. Choose the Subtotal command on the Data tab in Excel 2007 and later, or the Data menu in Excel 2003 and earlier.
  3. Select the Cases Sold field, and then click OK.
Figure 1: Use the Subtotal feature to automate inserting totals within a list of data.
Figure 2 shows the newly inserted subtotals, along with outlining controls at the left-hand side of the worksheet. If you click the 1 button, the list will collapse down to just the total rows, as shown in Figure 3. 
Figure 2: The Subtotal feature inserted a total after each change in the Product column.
Figure 3: Click the 1 button to collapse the list down to just the total rows.
Click on cell A1 and then press Ctrl-A to select the contiguous block of data. Press Ctrl-C to copy, and then in a new worksheet, press the Enter key to paste your data. At this point the aforementioned nuance reveals itself. One would think Excel would copy and paste just the visible rows that contain the totals, but instead, Excel includes all of the rows, as shown in Figure 4. 
Figure 4: Even though we thought we copied just the total rows, Excel pasted all of the rows.
Similarly, any formatting that you apply would affect the hidden rows as well. Here's how to take charge of the situation:
  1. As shown in Figure 5, select the cells that you wish to copy or format.
  2. Press Ctrl-G to display the Go To dialog box and then click the Special button.
  3. Double-click Visible Cells Only.
Figure 5: Use the Go To Special command to select just the visible rows for copying or formatting.
At this point, you can copy or format just the total rows. You can access the Go To Special command in other ways as well:
  • In any version of Excel, press F5 instead of Ctrl-G.
  • In Excel 2007 and later, choose the Find & Select command on the Home Tab and then choose Go To Special.
  • In Excel 2003 and earlier, choose Edit, Go To, and then click the Special button.
N.B.: You don't need to use the Go To Special command with filtered lists (the Filter command in Excel 2007 and later, or the AutoFilter command in Excel 2003 and earlier). Only the visible rows are affected when you copy or format filtered lists, but with the Subtotal feature, the extra step of Visible Cells Only will help you keep your sanity.
Read more articles by David Ringstrom. 
About the author:

David H. Ringstrom, CPA heads up Accounting Advisors, Inc., an Atlanta-based software and database consulting firm providing training and consulting services nationwide. Contact David at [email protected] or follow him on Twitter. David speaks at conferences about Microsoft Excel, and presents webcasts for several CPE providers, including AccountingWEB partner CPE Link.


Please login or register to join the discussion.

Works for me, thanks for the tip !

You're welcome! I appreciate the feedback!

I am using MS Excel v10. I am trying to step into my V.B. / Macro and add an entry that will insert a blank row after each line showing Total! Please tell me there is an easy way to do this. I am doing it manually now and when you have multiple sheets it becomes burdensome. Can you help me? Thanks, R, Dave

Manually inserting blank rows is going to be troublesome no matter how you approach it. My recommendation is to use this approach instead:

'Show total rows
ActiveSheet.Outline.ShowLevels RowLevels:=2

'Double the row height of the visible rows
Range("A1").CurrentRegion.SpecialCells(xlCellTypeVisible).RowHeight = 30

My initial findings regarding this effort are that it appears to be difficult. Is that the case? I had one suggestion, tried it and it failed :(
I was hoping that someone out there already pioneered this effort and had an answer for me. So to your knowledge there is no way to include the automatic entry in a Macro? Thanks for your help buddy, I really appreciate it! R, Dave

I didn't say that you couldn't do it, I said that writing such code would be difficult. I offered a two line solution that would accomplish the visual effect you're after. If you actually need/want to insert a blank row after each total, you can, you'll have to write a loop that looks at each row and determines if its visible or not and inserts rows accordingly, plus skips over the new rows you added. There are many user forums online that are well trafficked by other users that have the time and inclination to step you through the approach you're seeking.

Excellent. Now if only I can remember this for the next time

Extremelly useful, thanks a lot!

My pleasure! I'm glad that you found the technique helpful.

Brilliant advice. By far the best return on my Google search. Really useful. Thank you.

You're welcome! Thank you for taking a moment to share your thoughts! I'm so glad you found my article helpful.