ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Puvot Refresh (https://www.excelbanter.com/excel-programming/413523-puvot-refresh.html)

MichaelR

Puvot Refresh
 
I'm trying to write a macro to remove all of the fields that are in the
layout area of my pivot table. I found a macro online that did something
similar and I adapted it to look like this:

Sub PivotRefresh()
Dim pt As PivotTable
Dim pf As PivotField
Set pt = ActiveSheet.PivotTables(1)
For Each pf In pt.PivotFields
pf.Orientation = xlHidden
Next pf
End Sub

The problem, however, is that the macro doesn't always work. I originally
thought that it was because the data items are not named the same way as
their respective fields (i.e. Sum of.../Count of.../etc.) but sometimes the
macro clears the data fields. Sometimes it runs normally and other times the
following error message pops up: "Unable to set the Orientation property of
the PivotField class."

Is there any way that I can make this macro work? Please help.

Thanks,
Michael

Debra Dalgleish

Puvot Refresh
 
Instead of pt.PivotFields, try pt.VisibleFields

MichaelR wrote:
I'm trying to write a macro to remove all of the fields that are in the
layout area of my pivot table. I found a macro online that did something
similar and I adapted it to look like this:

Sub PivotRefresh()
Dim pt As PivotTable
Dim pf As PivotField
Set pt = ActiveSheet.PivotTables(1)
For Each pf In pt.PivotFields
pf.Orientation = xlHidden
Next pf
End Sub

The problem, however, is that the macro doesn't always work. I originally
thought that it was because the data items are not named the same way as
their respective fields (i.e. Sum of.../Count of.../etc.) but sometimes the
macro clears the data fields. Sometimes it runs normally and other times the
following error message pops up: "Unable to set the Orientation property of
the PivotField class."

Is there any way that I can make this macro work? Please help.

Thanks,
Michael



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


MichaelR

Puvot Refresh
 
Thank you.

"Debra Dalgleish" wrote:

Instead of pt.PivotFields, try pt.VisibleFields

MichaelR wrote:
I'm trying to write a macro to remove all of the fields that are in the
layout area of my pivot table. I found a macro online that did something
similar and I adapted it to look like this:

Sub PivotRefresh()
Dim pt As PivotTable
Dim pf As PivotField
Set pt = ActiveSheet.PivotTables(1)
For Each pf In pt.PivotFields
pf.Orientation = xlHidden
Next pf
End Sub

The problem, however, is that the macro doesn't always work. I originally
thought that it was because the data items are not named the same way as
their respective fields (i.e. Sum of.../Count of.../etc.) but sometimes the
macro clears the data fields. Sometimes it runs normally and other times the
following error message pops up: "Unable to set the Orientation property of
the PivotField class."

Is there any way that I can make this macro work? Please help.

Thanks,
Michael



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




All times are GMT +1. The time now is 07:20 PM.

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