Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot Table Reports Year to date Values limister Excel Discussion (Misc queries) 4 April 17th 09 06:57 AM
Create refresh button in worksheet to refresh Pivot Table Data Ron Excel Worksheet Functions 1 October 13th 07 01:20 AM
Pivot Table Year to Date Jim Thomlinson[_3_] Excel Programming 2 March 28th 05 08:39 PM
Setting up "Year to Date" Calculations in a Pivot Table Project64 Excel Worksheet Functions 1 March 22nd 05 01:50 AM
create a date from year, day and month Baerbel Excel Worksheet Functions 3 November 13th 04 06:46 PM


All times are GMT +1. The time now is 04:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"