Modify Pivot Excel 2003

Forestq

Active Member
Joined
May 9, 2010
Messages
482
Team,

pelase tell how can I add to my code "pivot cache" and how to create PivotTable in sheet call "PivotSheet" (which I`m creating by VBA).

this is my code:
Code:
Sub CreatePivot()
   
    On Error Resume Next
    Application.DisplayAlerts = False
    Sheets("PivotSheet").Delete
    On Error GoTo 0
    
    Worksheets.Add
    ActiveSheet.Name = "PivotSheet"
    ActiveWindow.DisplayGridlines = False
    
    
      Sheets("Sheet1").PivotTableWizard _
      SourceType:=xlDatabase, _
      SourceData:="A1:G40", _
     TableName:="Sales&Trans"
        
    With ActiveSheet.PivotTables("Sales&Trans")
        .PivotFields("Year").Orientation = xlPageField
        .PivotFields("Year").Position = 1
        .PivotFields("Store City").Orientation = xlRowField
        .PivotFields("Store City").Position = 1
        
        .PivotFields("Store Type").Orientation = xlRowField
        .PivotFields("Store Type").Position = 2
        
        .PivotFields("Period").Orientation = xlColumnField
        
        
        With .PivotFields("Transactions")
            .Orientation = xlDataField
            .Position = 1
        End With
        
        With .PivotFields("Sales")
            .Orientation = xlDataField
            .Position = 2
        End With
        
    End With
                 
 End Sub

thanks for your support!
regards,
PvK
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try:

Code:
Sub CreatePivot()
    On Error Resume Next
    Application.DisplayAlerts = False
    Sheets("PivotSheet").Delete
    On Error GoTo 0
    Worksheets.Add
    ActiveSheet.Name = "PivotSheet"
    ActiveWindow.DisplayGridlines = False
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "Sheet1!R1C1:R40C7").CreatePivotTable TableDestination:= _
        "PivotSheet!R1C1", TableName:="Sales&Trans", DefaultVersion:= _
        xlPivotTableVersion10
    With ActiveSheet.PivotTables("Sales&Trans")
        .PivotFields("Year").Orientation = xlPageField
        .PivotFields("Year").Position = 1
        .PivotFields("Store City").Orientation = xlRowField
        .PivotFields("Store City").Position = 1
        .PivotFields("Store Type").Orientation = xlRowField
        .PivotFields("Store Type").Position = 2
        .PivotFields("Period").Orientation = xlColumnField
        With .PivotFields("Transactions")
            .Orientation = xlDataField
            .Position = 1
        End With
        With .PivotFields("Sales")
            .Orientation = xlDataField
            .Position = 2
        End With
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top