Wilfried_1983
New Member
- Joined
- Jul 17, 2008
- Messages
- 15
Hey guys, I have the following problem.
I have a Pivot Table that is linked to an Access Database.
In order to get the required results for my management report I need to remove and drop a lot of column, row and page fields which requires a lot of time.
I have recorded and tweaked over 40 macros to perform these routines. However, the catch is that I manually need to remove all items from the Pivot Table before running a new macro.
Trying to avoid this, I wrote this little piece of code.
The part of removing the datafields on its own works, however the part of removing the column, row and pagefields doesn´t.
I found that there are the following classes in the VBA library: xlColumnField, xlPageField, xlRowField. Should I incorporate these into the code, if so, how?
This is the code I have written so far:
Thanks in advance
I have a Pivot Table that is linked to an Access Database.
In order to get the required results for my management report I need to remove and drop a lot of column, row and page fields which requires a lot of time.
I have recorded and tweaked over 40 macros to perform these routines. However, the catch is that I manually need to remove all items from the Pivot Table before running a new macro.
Trying to avoid this, I wrote this little piece of code.
The part of removing the datafields on its own works, however the part of removing the column, row and pagefields doesn´t.

I found that there are the following classes in the VBA library: xlColumnField, xlPageField, xlRowField. Should I incorporate these into the code, if so, how?
This is the code I have written so far:
Code:
Sub TestClearAll()
Sheets("PT").Select
Dim PT As PivotTable, ptField As PivotField, ptColumn As PivotField, ptRowField As PivotField, ptPageField As PivotField
Set PT = ActiveSheet.PivotTables("PT")
For Each ptField In PT.DataFields
ptField.Orientation = xlHidden
Next ptField
For Each ptColumn In PT.ColumnFields
PT.ColumnFields.Orientation = xlHidden
Next ptColumn
For Each ptRowField In PT.RowFields
PT.RowFields.Orientation = xlHidden
Next ptRowField
For Each ptPageField In PT.PageFields
PT.PageFields.Orientation = xlHidden
Next ptPageField
Set PT = Nothing
End Sub
Thanks in advance