Pivot Data fields - removal of all (value) fields

B

Bradley Searle

Hi,

I'm trying to write a macro that removes all items in the "data" field of a
pivot table. To remove a particular field, in this case the field called "Sum
of FP01" you could use a macro such as this:

ActiveSheet.PivotTables("Central").PivotFields("Sum of FP01").Orientation = _
xlHidden

However if you do not have that field in the table it creates and error.

How would I say "remove ANY data from the data field?"

Many thanks, Brad
 
P

paul.robinson

Hi

Dim PF as PivotField
With ActiveSheet.PivotTables("Central")
For Each PF In .PivotFields
.Orientation = xlHidden
Next PF
End With

regards
Paul

ActiveSheet.PivotTables("Central").PivotFields("Sum of
FP01").Orientation = _
 
B

Bradley Searle

Thanks for your help Paul!

I think your code will probably take all fields away (not just the
datafields) - but having not tested it I'm not 100%.

I've not tested it because I found a solution - it is:

ActiveSheet.PivotTables("Central").DataPivotField.Orientation = xlHidden

This simply removes all the data fields, leaving row, column and filter
fields in tact.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top