XL97: Incorrect Field Names Appear in PivotTable Field Dialog Box

ID: Q202232


The information in this article applies to:


SYMPTOMS

In the PivotTable Field dialog box, the Hide Items list may display field names that are not contained within the source data range of the PivotTable.


CAUSE

This problem occurs when the following conditions are true:

-and-


WORKAROUND

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft Support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/refguide/
The following sample macro code deletes all of the fields in the PivotTable and then refreshes the PivotTable. Only the fields that are currently in the source data range will be displayed in the PivotTable Field dialog box.
  1. Write down the name of the worksheet that contains the PivotTable (for example, "Sheet1") and the name of the PivotTable (for example, "PivotTable1"). To determine the name of a PivotTable, right-click any area of the PivotTable and click Options. The PivotTable Options dialog box displays the name of the PivotTable. Click OK to close the dialog box.


  2. On the Tools menu point to Macro, and click Visual Basic Editor. Or, press ALT+F11.


  3. On the Insert menu, click Module.


  4. Enter the following code:
    
    Sub Delete_Fields()
       On Error Resume Next
       For Each pvtfield In Worksheets("X").PivotTables("Y").PivotFields
          For Each pvtitem In pvtfield.PivotItems
             pvtitem.Delete
          Next
       Next
       ActiveSheet.PivotTables("Y").RefreshTable
    End Sub 
    where "X" is the name of the worksheet you wrote down in step 1 and "Y" is the name of the PivotTable you wrote down in step 1.


  5. On the File menu, click Close and Return to Microsoft Excel.


  6. On the Tools menu, point to Macro and click Macros. In the list of macros, click Delete_Fields, and then click Run.



STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.

Additional query words: XL97


Keywords          : kbdta kbdtacode KbVBA 
Version           : WINDOWS:97
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: June 17, 1999