ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Changing the CurrentPage items in a Pivot Table (https://www.excelbanter.com/excel-programming/417865-changing-currentpage-items-pivot-table.html)

John

Changing the CurrentPage items in a Pivot Table
 
Hello,

I have an already generated Pivot Table which i would like to amend the
CurrentPageitems programmatically.

I have a list of fields in a tab. I am able to select fields in this list
that i would then like to build into my Pivot table as CurrentPage items.
Using:
For i = 1 To MyRange.Rows.Count

If Len(Application.WorksheetFunction.Index(MyRange, i, 2)) 0 Then
MySelection = Application.WorksheetFunction.Index(MyRange, i, 1)
ActiveSheet.PivotTables("PivotTable1").PivotFields ("" &
MySelection & "").CurrentPage = "(All)"
End If

Next

I get the runtime error 1004 and the message "Unable to get the PivotFields
Property of the Pivot Table Class".

Guess what this comes down to is their is a much better way of doing this.
Would anyone be able to help me with this please?

Thanks
John




Daniel.C

Changing the CurrentPage items in a Pivot Table
 
Hello.
This should work if your fields are already defined as page fields.
--
Regards.
Daniel
"John" a écrit dans le message de news:
...
Hello,

I have an already generated Pivot Table which i would like to amend the
CurrentPageitems programmatically.

I have a list of fields in a tab. I am able to select fields in this list
that i would then like to build into my Pivot table as CurrentPage items.
Using:
For i = 1 To MyRange.Rows.Count

If Len(Application.WorksheetFunction.Index(MyRange, i, 2)) 0 Then
MySelection = Application.WorksheetFunction.Index(MyRange, i, 1)
ActiveSheet.PivotTables("PivotTable1").PivotFields ("" &
MySelection & "").CurrentPage = "(All)"
End If

Next

I get the runtime error 1004 and the message "Unable to get the
PivotFields
Property of the Pivot Table Class".

Guess what this comes down to is their is a much better way of doing this.
Would anyone be able to help me with this please?

Thanks
John







All times are GMT +1. The time now is 09:16 AM.

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