Search code examples
excelvbafieldpivot-tablefieldlist

How can I use VBA to check the box next to a Pivot Table field to show the field in the table?


I was hoping I could use a code like this:
Worksheets("Sheet2").PivotTables("PivotTable3").PivotFields("Name").Visible = True
But it is not working. I keep getting the error: "Run-time Error 438 Object doesn't support this property or method.

Simply, I want to check a specific box next to the field name in the pivot table field list. Any idea how I could go about doing this?

Thanks!


Solution

  • Use PivotTable.AddFields method

    Worksheets("Sheet2").PivotTables("PivotTable3").AddFields("Name")