Search Contextures Sites ![]()
Last updated: July 3, 2010 1:06 PM
Excel Pivot Table Tutorial -- Clear Old Items
- Manually Clear Old Items
- Change the Retain Items Setting in Excel 2007
- Programmatically Clear Old Items -- Excel 2002 and later
- Programmatically Clear Old Items -- Excel 97/2000
Download the zipped sample file for this pivot table tutorial
Table of Contents
Old Items Remain in Pivot Field Dropdowns
The data in the pivot table source may change, and items that were previously in the source are no longer included. For example, some sales reps may leave the company, and the names of their replacements appear in the source table.
Even after you refresh the pivot table, the names of the old sales reps will appear, along with the new names. In the list at right, Cartier has replace Gill, but Gill still appears in the list.
This pivot table tutorial shows how you can clear the old items either manually or programmatically.
Change the Retain Items Setting in Excel 2007
To prevent old items from being retained in an Excel 2007 pivot table, you can change an option setting:
- Right-click a cell in the pivot table
- Click on PivotTable options
- Click on the Data tab
- In the Retain Items section, select None from the drop down list.
- Click OK, then refresh the pivot table.
To view the steps in a short video, click here
Programmatically Clear Old Items -- Excel 97/Excel 2000
In previous versions of Excel, run the following code to clear the old items from the dropdown list.
![]()
Sub DeleteOldItemsWB() 'pivot table tutorial by contextures.com 'gets rid of unused items in PivotTable ' based on MSKB (202232) Dim ws As Worksheet Dim pt As PivotTable Dim pf As PivotField Dim pi As PivotItem On Error Resume Next For Each ws In ActiveWorkbook.Worksheets For Each pt In ws.PivotTables pt.RefreshTable pt.ManualUpdate = True For Each pf In pt.VisibleFields If pf.Name <> "Data" Then For Each pi In pf.PivotItems If pi.RecordCount = 0 And _ Not pi.IsCalculated Then pi.Delete End If Next pi End If Next pf pt.ManualUpdate = False pt.RefreshTable Next pt Next ws End SubDownload the zipped sample file for this pivot table tutorial
![]()
![]()
Contextures Inc., Copyright ©2010
All rights reserved.