Results 1 to 8 of 8

Automated Pivot Generation

Threaded View

AnthonyWB Automated Pivot Generation 06-03-2010, 10:04 AM
romperstomper Re: Automated Pivot Generation 06-03-2010, 10:09 AM
AnthonyWB Re: Automated Pivot Generation 06-03-2010, 10:24 AM
romperstomper Re: Automated Pivot Generation 06-03-2010, 10:37 AM
AnthonyWB Re: Automated Pivot Generation 06-03-2010, 11:15 AM
romperstomper Re: Automated Pivot Generation 06-03-2010, 11:20 AM
AnthonyWB Re: Automated Pivot Generation 06-03-2010, 11:21 AM
AnthonyWB Re: Automated Pivot Generation 06-03-2010, 11:36 AM
  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Automated Pivot Generation

    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.
    Last edited by AnthonyWB; 06-03-2010 at 11:37 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1