ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Pivot Table Clear All Fiels (https://www.excelbanter.com/excel-discussion-misc-queries/192255-pivot-table-clear-all-fiels.html)

MichaelR

Pivot Table Clear All Fiels
 
Hi,

I'm trying to write a macro that will return a pivot table to its beginning
format with all fields listed in the PivotTable Field List but without any of
them being selected. The purpose of the macro is for the user to be able
start from scratch in a very easy way. However, I don't want to delete the
PivotTable and then reinsert it because it takes a long time to import the
data from access. Is there any way that I could do something like this:

ActiveSheet.PivotTables("PivotTable1").PivotFields ("Product").Orientation = _
xlHidden

for all page fields, column fields, row fields and data values (regardless
of their name or how many of them are being used)?

Thanks,
Michael

[email protected]

Pivot Table Clear All Fiels
 
On Jun 23, 6:07*pm, MichaelR
wrote:
Hi,

I'm trying to write a macro that will return a pivot table to its beginning
format with all fields listed in the PivotTable Field List but without any of
them being selected. The purpose of the macro is for the user to be able
start from scratch in a very easy way. However, I don't want to delete the
PivotTable and then reinsert it because it takes a long time to import the
data from access. Is there any way that I could do something like this:

ActiveSheet.PivotTables("PivotTable1").PivotFields ("Product").Orientation = _
* * * * xlHidden

for all page fields, column fields, row fields and data values (regardless
of their name or how many of them are being used)?

Thanks,
Michael


Try SiSense. They have easier pivot tables and connect to excel.
http://www.sisense.com

Debra Dalgleish

Pivot Table Clear All Fiels
 
You could use something like this:

'====================
Sub ClearPivot()

On Error Resume Next

Dim pt As PivotTable
Dim pf As PivotField

Set pt = ActiveSheet.PivotTables(1)
With pt
For Each pf In .VisibleFields
pf.Orientation = xlHidden
Next pf
End With

ActiveWorkbook.ShowPivotTableFieldList = True

End Sub
'====================



MichaelR wrote:
Hi,

I'm trying to write a macro that will return a pivot table to its beginning
format with all fields listed in the PivotTable Field List but without any of
them being selected. The purpose of the macro is for the user to be able
start from scratch in a very easy way. However, I don't want to delete the
PivotTable and then reinsert it because it takes a long time to import the
data from access. Is there any way that I could do something like this:

ActiveSheet.PivotTables("PivotTable1").PivotFields ("Product").Orientation = _
xlHidden

for all page fields, column fields, row fields and data values (regardless
of their name or how many of them are being used)?

Thanks,
Michael



--
Debra Dalgleish
Contextures
www.contextures.com/tiptech.html
Blog: http://blog.contextures.com


MichaelR

Pivot Table Clear All Fiels
 
Debra,

Thank you so much for your help. The macro worked wonderfully!

Best wishes,
Michael


All times are GMT +1. The time now is 06:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com