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: Reducing File Sizes for Workbooks with PivotTables.

Reducing File Sizes for Workbooks with PivotTables

Written by Allen Wyatt (last updated August 27, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


3

PivotTables are great for certain types of data analysis. Since PivotTables do quite a bit of number crunching, one of the techniques Excel uses to process them faster is to create an "intermediate dataset" to work with. This intermediate dataset, by default, is stored with the worksheet, so PivotTables can increase the size of your workbooks, sometimes dramatically.

If your workbook contains multiple PivotTables, all based on a single data source, Excel may create an intermediate dataset for each PivotTable, instead of using one intermediate dataset. This, of course, could increase the size of your workbook very rapidly.

You can control how Excel creates the intermediate dataset by modifying the options you use when you create the PivotTable.

  1. Create your PivotTable as you normally would.
  2. Display the Options tab (Excel 2007 and Excel 2010) or the Analyze tab (Excel 2013) or the PivotTable Analyze tab (later versions of Excel) of the Ribbon. (This tab is visible only when you select a cell in the PivotTable.)
  3. At the left end of the Ribbon click the Options tool in the PivotTable group. Excel displays the PivotTable Options dialog box.
  4. Make sure the Data tab is displayed. (See Figure 1.)
  5. Figure 1. The Data tab of the PivotTable Options dialog box.

  6. Clear the Save Source Data with File check box.
  7. Choose the Refresh on Open check box.
  8. Click on OK to close the PivotTable Options dialog box.

You don't need to choose the Refresh on Open check box (step 6) if you don't want to, but if you don't, you will need to remember to manually refresh the PivotTable every time you open the workbook.

If you already have quite a few PivotTables in your workbook, and you don't want to go through the process of creating them again, you can use a macro to step through the PivotTables and modify the caching index and turn off the saving of the intermediate data to disk. The following macro will accomplish these tasks:

Sub PTReduceSize()
    Dim wks As Worksheet
    Dim PT As PivotTable

    For Each wks In ActiveWorkbook.Worksheets
        For Each PT In wks.PivotTables
            PT.RefreshTable
            PT.CacheIndex = 1
            PT.SaveData = False
        Next
    Next
End Sub

Once the macro runs (it won't take long), you should save your workbook using the Save As option. This will write a new workbook file, and you will be able to compare how much this change reduced the size of your workbook. Remember, however, that with the intermediate data not being saved to disk, the refreshing of the PivotTables takes longer when you first open the workbook.

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 (8669) 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: Reducing File Sizes for Workbooks with PivotTables.

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

Cannot Convert a Document File to a Readable Document

Open a Word document file, and you can start to make edits and changes to your heart's content. But what happens if the ...

Discover More

Inserting Worksheet Values with a Macro

Macros are often used to process information in a worksheet. You may need your macro to change the values stored in ...

Discover More

Inserting a Cross-Reference to Text

Cross-referencing is a great feature of Word that allows you to add references to text in various places of your ...

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 (ribbon)

Expanding PivotTable Rows to Sheets

PivotTables are a great way to work with large quantities of data in an intelligent manner. Sometimes, however, you just ...

Discover More

Using Classic PivotTable Layout as the Default

Are you attached to the classic PivotTable layout? Looking for a way to make that layout the default for new PivotTables? ...

Discover More

Empty PivotTable Cells Don't Show as Blank

You can configure Excel so that it displays special text within blank PivotTable cells. Here's how to make the changes ...

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 2 + 2?

2017-03-02 07:06:30

Dave Proctor

I have a 199mb workbook. It contains 1 x data worksheet (12k rows x 50 columns, and about 6 pivot tables running off it.
Your macro reduced the size of the workbook to 159mb.
Unfortunately on 1 of the worksheets the reduction macro when run, killed off 2 x calculated fields.
I'm not sure if there is a way around this, would appreciate comments if anyone has time.
Thanks for a great resource!


2016-03-10 10:37:27

Allison

This worked great for my workbook as well. Went from 33MB to 14MB. Thanks!


2015-10-05 10:15:53

Barbara

I have several cumbersome workbooks with PivotTables linked to outside sources. I just used this tip to take one from 5,600kb down to 127kb! Thanks Allen!


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.