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: Moving Subtotals.

Moving Subtotals

Written by Allen Wyatt (last updated February 12, 2022)
This tip applies to Excel 97, 2000, 2002, and 2003


David was adding subtotals (Data | Subtotals) 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 that you must run the macro with a range of cells selected, and part of that selection must include column S.)

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 (2119) 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: 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

Forcing the Properties Dialog Box to Appear

Do you want the Properties dialog box to appear when you first save a Word document? You can configure Word so that it ...

Discover More

Changing the Starting Page Number

Got page numbers in your worksheet printout? You may want to have those page numbers start with a number other than 1. ...

Discover More

Determining the Length of a Non-Document Text File

If you use a macro to create and work with text files, you can find out the length of those files using a simple command. ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (menu)

Copying Subtotals

If you have added subtotals to your worksheet data, you might want to copy those subtotals somewhere else. This is easy ...

Discover More

Using Subtotals and Totals

You can insert subtotals and totals in your worksheets by using either a formula or specialized tools. This tip explains ...

Discover More

Excel Refuses to Put Page Breaks between Subtotal Groups

Page breaks not appearing where you expect them in your subtotaled data? It could be because of a setting you made in ...

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 8 - 5?

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.