Changing the CurrentPage items in a Pivot Table

  • Thread starter Thread starter John
  • Start date Start date
J

John

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
 
Hello.
This should work if your fields are already defined as page fields.
 

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

Back
Top