Hello,
I'm trying to automatically set the current year and next year in a pivot table using VBA. This is what I have currently
Dim CurrentYear as Variant
Dim NextYear as Variant
CurrentYear = Year(Now())
NextYear = Year (Now())+1
With ActiveSheet.PivotTables("PivotTable1").PivotFields("YR")
.PivotItems("CurrentYear").Visible = True
.PivotItems("NextYear").Visible = True
End With
Every time I run it, I get an error. Can someone please help?
Thanks,
I'm trying to automatically set the current year and next year in a pivot table using VBA. This is what I have currently
Dim CurrentYear as Variant
Dim NextYear as Variant
CurrentYear = Year(Now())
NextYear = Year (Now())+1
With ActiveSheet.PivotTables("PivotTable1").PivotFields("YR")
.PivotItems("CurrentYear").Visible = True
.PivotItems("NextYear").Visible = True
End With
Every time I run it, I get an error. Can someone please help?
Thanks,