My pivot table has, in the Data field, an item called MOS2. MOS2 has Expenses for the 12 months of the year. The months are formatted as 01 through 12. In another workbook I've got a list of applicable months. I'm trying to get the syntax right to allow the values from my applicable months to be used by my macro to reset the pivot table to those months, by referencing the other workbook. However, my code fails with a Run-Time error 1004 ' "Unable to get the PivotItems Property of the PivotField Class". I'd appreciate any help in getting the syntax right.
Thanks,
John
Thanks,
John
Code:
With ActiveSheet.PivotTables("PivotTable1").PivotFields("MOS2")
.PivotItems(Workbooks("2BDeleted.xls").Sheets("Lookups").Range("$D2")).Visible = True
.PivotItems(Workbooks("2BDeleted.xls").Sheets("Lookups").Range("$D3")).Visible = True
.PivotItems(Workbooks("2BDeleted.xls").Sheets("Lookups").Range("$D4")).Visible = True
.PivotItems(Workbooks("2BDeleted.xls").Sheets("Lookups").Range("$D5")).Visible = True
.PivotItems(Workbooks("2BDeleted.xls").Sheets("Lookups").Range("$D6")).Visible = True
.PivotItems(Workbooks("2BDeleted.xls").Sheets("Lookups").Range("$D7")).Visible = True
.PivotItems(Workbooks("2BDeleted.xls").Sheets("Lookups").Range("$D8")).Visible = True
.PivotItems(Workbooks("2BDeleted.xls").Sheets("Lookups").Range("$D9")).Visible = True
.PivotItems(Workbooks("2BDeleted.xls").Sheets("Lookups").Range("$D10")).Visible = True
.PivotItems(Workbooks("2BDeleted.xls").Sheets("Lookups").Range("$D11")).Visible = True
.PivotItems(Workbooks("2BDeleted.xls").Sheets("Lookups").Range("$D12")).Visible = True
End With