Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. 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: Moving Subtotals.

Moving Subtotals

Written by Allen Wyatt (last updated June 13, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


3

David was adding subtotals (Data tab of the ribbon, in the Outline group) to large worksheets and looking for a way to move the subtotal cells to different cells. For instance, assume that when Excel added the automatic subtotals, they were added in column S, and the SUBTOTAL formula added by Excel referred to ranges of cells in column S. David wanted to move the SUBTOTAL formulas (and only those formulas) out of column S to column T, and have the formulas still refer to detail in column S.

One option is to go through and move the SUBTOTAL formulas, one at a time, to the desired locations. (You would use Ctrl+X and Ctrl+V to move the cells, rather than Ctrl+C and Ctrl+V to merely create copies of the cells.) If the worksheets are large, with many subtotals, this can become very tedious very quickly.

Tedium in Excel is often the primary impetus for creating a macro. This case is no exception. It is possible to create a macro that will do the actual move of the SUBTOTAL formulas. Consider the following example:

Sub MoveSubtotals()
    Dim rCell As Range
    Dim rng As Range
    Dim iCol As Integer
    Dim iOffset As Integer

    iCol = 19  '19 is Column S
    iOffset = 1 'Positives go right, negatives go left
    Set rng = Intersect(Selection.CurrentRegion, Columns(iCol))
    For Each rCell In rng
        If InStr(rCell.Formula, "SUBTOTAL") Then
            rCell.Offset(0, iOffset).Formula = _
                rCell.Formula
            rCell.ClearContents
        End If
    Next
End Sub

This example works by examining each cell selected in column S. If the formula in the cell contains the word SUBTOTAL, then the formula is copied one column to the right, in column T, and deleted from the cell in column S. You can change the distance left or right that the subtotals are moved by simply changing the value assigned to the iOffset variable.

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 (8643) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Moving Subtotals.

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

Unwanted Graph Paper Effect

When you open a document or start to use Word, do you see a background that looks like graph paper? It could be because ...

Discover More

Calculating the Day of the Year

Need to know what day of the year a certain date is? You can figure it out easily using the formulas in this tip.

Discover More

Counting Ports of Call with a PivotTable

A PivotTable is a great way to aggregate and analyze data. Sometimes, though, it can be difficult to figure out how to ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Using Check Boxes

Check boxes, just like those used in Windows dialog boxes, can be a great addition to a worksheet. Here's how to add them ...

Discover More

Using Multiple Print Settings

Do you have a worksheet from which you need to print only portions of the data available? There are two ways you can ...

Discover More

Converting Imported Information to Numeric Values

If the information you import into Excel is treated as text by the program, you may want to convert it to numeric values. ...

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 6 - 0?

2024-06-18 12:51:32

J. Woolley

@Rick Leisner
Your suggestion is excellent.
The Tip's macro depends upon the range that was selected before it was initiated. And it might miss the final Grand Total. It would be more reliable if the following statement
Set rng = Intersect(Selection.CurrentRegion, Columns(iCol))
was replaced by this statement
Set rng = Intersect(ActiveSheet.UsedRange, Columns(iCol))
Also, Columns(iCol) can be replaced by Columns("S"), which is perhaps easier to understand.


2024-06-13 16:36:27

Rick Leisner

Does inserting a cell and shifting right work? And then hit F4 everywhere else you want to do it. That would be easier than ^X and ^V. Or am I misunderstanding?


2020-08-03 09:56:16

RKeev

Try selecting your subtotals formulas, replace the equals sign with ppp using the find and replace, then copy that area and paste to the desired area. Then run the find and replace again replacing the ppp with the equals sign.


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.