Senerio
I am creating report that copies cells from a "read only" pivot table and paste them to a different worksheet. I need the "year" field in the pivot table to only show the year that the user imputs into a cell.
This is the code that I have now:
Vyear = ActiveSheet.Range("H17")
Windows("SCTS SGA Analysis File SCTS Rollup.xls").Activate
Sheets("sheet1").Activate
For Each PivotYear In ActiveSheet.PivotTables("PivotTable1").PivotField("Year").PivotItems()
If PivotYear = Vyear Then
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Year")
.PivotItems(PivotYear).Visible = True
End With
Else
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Year")
.PivotItems(PivotYear).Visible = False
End With
End If
Next
When I recorded he macro and manually choose 2011 this is what appeared
Windows("SCTS SGA Analysis File SCTS Rollup.xls").Activate
ActiveSheet.PivotTables("PivotTable1").PivotFields("Year").CurrentPage = _
"(All)"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Year")
.PivotItems("(blank)").Visible = False
.PivotItems("2008").Visible = False
.PivotItems("2009").Visible = False
.PivotItems("2010").Visible = False
.PivotItems("2011").Visible = True
.PivotItems("2012").Visible = False
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("Year"). _
EnableMultiplePageItems = True
Unfortunately, I cannot post the workbooks because their content cannot be shared
Bookmarks