Hello everyone. I have code written which generates pivot tables. Please see a snipett of the code below:
Set wks1 = wb1.Sheets.Add
Set pc1 = wb1.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"'105'!R1C1:R11500C48", Version:=xlPivotTableVersion12)
Set pt1 = pc1.CreatePivotTable(TableDestination:=wks1.Range("A3"), TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion12)
With pt1
With .PivotFields("Desk " & Chr(10) & "ID")
.Orientation = xlPageField
.Position = 1
End With
With .PivotFields("Asset_Liability")
.Orientation = xlRowField
.Position = 1
End With
With .PivotFields("Bond_Swap")
.Orientation = xlRowField
.Position = 2
End With
With .PivotFields("Asset_Liability")
.Orientation = xlColumnField
.Position = 1
End With
With .PivotFields("Bond_Swap")
.Orientation = xlColumnField
.Position = 2
End With
With .PivotFields("Bond_Swap")
.Orientation = xlRowField
.Position = 1
End With
.AddDataField .PivotFields("MTM_USD_30-apr-2010"), "Count of MTM_USD_30-apr-2010", xlCount
With .PivotFields("Count of MTM_USD_30-apr-2010")
.Caption = "Sum of MTM_USD_30-apr-2010"
.Function = xlSum
End With
With wks1.Cells
.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
.EntireColumn.AutoFit
End With
With .PivotFields("Desk " & Chr(10) & "ID")
.CurrentPage = "(All)"
.EnableMultiplePageItems = True
.PivotItems("CLIENT").Visible = False
.PivotItems("EQTY").Visible = False
.PivotItems("IDA").Visible = False
.PivotItems("IDACLT").Visible = False
.PivotItems("IFFM").Visible = False
.PivotItems("LOAN").Visible = False
.PivotItems("MLOAN").Visible = False
.PivotItems("XPOOL").Visible = False
.PivotItems("(blank)").Visible = False
End With
With .PivotFields("Bond_Swap")
.PivotItems("CSWAP").Visible = False
.PivotItems("ISWAP").Visible = False
.PivotItems("FALSE").Visible = False
End With
With .PivotFields("Asset_Liability")
.Orientation = xlRowField
.Position = 2
.PivotItems("Asset").Visible = False
End With
With .PivotFields("CM_FAS157_Levels")
.Orientation = xlColumnField
.Position = 1
.PivotItems("3").Visible = False
.PivotItems("#N/A").Visible = False
.PivotItems("3").Visible = True
End With
With .PivotFields("Bond_Swap")
.Orientation = xlColumnField
.Position = 2
End With
With .PivotFields("Asset_Liability")
.Orientation = xlColumnField
.Position = 3
End With
With .PivotFields("Bond_Swap")
.Orientation = xlRowField
.Position = 1
End With
With .PivotFields("Asset_Liability")
.Orientation = xlRowField
.Position = 2
End With
End With
ActiveSheet.Name = "Bonds"
Range("B6").Select
Selection.ShowDetail = True
Sheets("Sheet4").Name = "Bond_Details"
Now here is the deal, rather than have hard coded dates as in
.AddDataField .PivotFields("MTM_USD_30-apr-2010"), "Count of MTM_USD_30-apr-2010", xlCount
With .PivotFields("Count of MTM_USD_30-apr-2010")
.Caption = "Sum of MTM_USD_30-apr-2010"
I would like to pass a global variable fDate? Any suggestions on how to go about this.
Bookmarks