![]() |
I want to create a Year to date button for a pivot table
Sub HideItems()
Dim pi As PivotItem Dim pf As PivotField Dim s As String, dt As Date With ActiveSheet.PivotTables("PivotTable2") .ManualUpdate = True Set pf = .PivotFields("Month") pf.AutoSort xlManual, pf.SourceName For Each pi In pf.PivotItems s = pi.Name dt = CDate(s) If Year(dt) < Year(Date) Then pi.Visible = False End If Next pf.AutoSort xlAscending, pf.SourceName .ManualUpdate = False End With End Sub -- Regards, Tom Ogilvy "Aaron" wrote: My button has this code now to control the Page feild of the PT: With ActiveSheet.PivotTables("PivotTable2").PivotFields ("Month") .PivotItems("9/30/2006").Visible = False .PivotItems("10/31/2006").Visible = False .PivotItems("11/30/2006").Visible = False .PivotItems("12/31/2006").Visible = False End With Thus leaving only the 2007 months visable, thus creating a YTD view. But when the year flips to 2008 I want the code to automatically Hide all 12 months in 2007 as well. I was thinking maybe I could set all pivotitems in pivotfeild Month to false if < cell A1 which I could set a formula in. What would this code look like, or is there a better way? |
All times are GMT +1. The time now is 03:00 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com