LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro to select dates in the page field of a pivot table

The below macro is suppose to create a sheet, add a pivot table and
then a data table that looks up pivot table data. Everything works
great except that the pivot table needs to be limited to data with a
specific date based on a cell entered by the user. The relavent lines
contain the variable B. I have tried defining B as a date and setting
the pivotfield = to the input cell directly. I have succesfully used
similar code with numbers such as 19. Is there something different
about dates?

Thanks!

Sub LFMStates()

X = "States"
Y = "LFM States breakout"
Z = "LFMStates"
A = "States!R3C10"
B = Worksheets("Input").Range("G7").Value
Application.ScreenUpdating = False
On Error Resume Next
Set wSheet = Worksheets(X)
If wSheet Is Nothing Then
Sheets.Add.Name = X
Sheets(X).Select

ActiveWorkbook.Worksheets("Graphs").PivotTables("P ivotTable1").PivotCache.
_
CreatePivotTable TableDestination:=A, TableName:=X
With ActiveSheet.PivotTables(X)
.PivotFields("Bureau State").Orientation = xlRowField
.PivotFields("Year").Orientation = xlColumnField
.PivotFields("Valued As Of Date").Orientation = xlPageField
.AddDataField
ActiveSheet.PivotTables(X).PivotFields("Incurred Limited"), "Sum of
Incurred Limited", xlSum
End With
ActiveSheet.PivotTables(X).PivotFields("Valued As Of
Date").CurrentPage = B
ActiveWorkbook.ShowPivotTableFieldList = False
Application.CommandBars("PivotTable").Visible = False
ActiveSheet.PivotTables(X).ManualUpdate = True
'Gets state list from defintion tab, sets years, and fills table with
formulas that lookup the pivot table values
Range("A1").Select
Sheets("Definitions").Range("AB1:AC52").Copy
Destination:=ActiveCell
Range("C1").Formula = "=YEAR(EffDate)"
Range("D1").FormulaR1C1 = "=RC[-1]-1"
Range("D1").Copy Destination:=Range("D1:H1")
Range("C2").Formula = "=IF(ISERROR(GETPIVOTDATA(""Incurred
Limited"",$J$1,""Year"",C$1,""Bureau
State"",$A2)),0,GETPIVOTDATA(""Incurred
Limited"",$J$1,""Year"",C$1,""Bureau State"",$A2))"
Range("C2").Copy Destination:=Range("C2:H52")
Range("C2:H52").NumberFormat = "_(* #,##0_);_(* (#,##0);_(*
""-""??_);_(@_)"
Cells.EntireColumn.AutoFit
Else
If MsgBox(Y & " already completed. Keep existing analysis?",
vbYesNo) = vbNo Then
Application.DisplayAlerts = False
Sheets(X).Delete
Application.DisplayAlerts = True
Run (Z)
Else
MsgBox "You Cancelled"
End If
End If
Application.ScreenUpdating = True
End Sub

 
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
Excel 2007 Pivot Tables - Page Field Row Height; Disable Select MultItems delecto Excel Discussion (Misc queries) 0 October 31st 08 09:28 PM
Field Select in a Pivot Table Vicki Excel Discussion (Misc queries) 2 May 12th 06 08:28 PM
Pivot Table Page Field Neily Excel Discussion (Misc queries) 3 February 24th 05 01:23 PM
disable mulitple select on pivot page field belinda Excel Programming 0 July 12th 04 02:22 PM
Pivot Table Page Field Todd Huttenstine Excel Programming 2 May 6th 04 04:24 PM


All times are GMT +1. The time now is 08:30 AM.

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"