View Single Post
  #2 (permalink)  
Old November 5th, 2003, 03:54 PM
taliesin taliesin is offline
Authorized User
Join Date: Jun 2003
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts

Was looking thru this forum for something else (UserForm question) and saw this old topic. Don't know if you'll check in, but I've written a VBA program to generate several different PivotTable layouts, copy each table layout to a new worksheet and format the data nicely for our Sales staff.

I believe your first problem is that the .DataFields property returns a read-only (according to the Help file for the DataFields property) collection of fields that have their .Orientation property set to xlDataField.

What you want to do is access the appropriate PivotField that happens to be currently assigned as an xlDataField and change it to xlHidden.

I do not change the data fields in my app, but here is my code to setup one of my data fields:

    With ActiveSheet.PivotTables("DataPivot").PivotFields(T HIS_FISCAL_MONTH)
        .Orientation = xlDataField
        .Caption = THIS_FISCAL_CAPTION
        .Position = 1
        .Function = xlSum
    End With

The constant THIS_FISCAL_MONTH is the column name in the worksheet that I am making into a data field, the other constant is the displayed data field caption. Using the constants allows me to easily change these parameters every month for the new report.

So, if I wanted to hide a data field I would change my code in the following manner:

    With ActiveSheet.PivotTables("DataPivot").PivotFields(T HIS_FISCAL_MONTH)
        .Orientation = xlHidden
    End With

or much simplified (and not fully qualified):
.PivotFields(THIS_FISCAL_MONTH).Orientation = xlHidden

I believe this will do the trick for you.
Reply With Quote