VBA creating a PivotTable

Sub pivot table ()
Dim the PTC of As PivotCache
Dim PVT. Of As a PivotTable
Dim RNG the Range of As
the Set RNG = Sheet1.Range ( "A1: D45") 'Data Source
Set PTC = ActiveWorkbook.PivotCaches.Create (SourceType: = xlDatabase, SourceData: = RNG, Version: = xlPivotTableVersion14)
the Set PVT. = PTC.CreatePivotTable (TableDestination: the Range = ( "h1 of"), the TableName: = "test perspective", DefaultVersion: = xlPivotTableVersion14)
the Set RNG = Nothing 'releases the object variable
With PVT

Remove the coding field subtotal function representative Subtotals (1) = false index 1 (auto) is false, all other values ​​will be set to False. If you need subtotals function is set to true or not sentence; End With the Set the PTC = Nothing the Set PVT = Nothing End Sub
















Guess you like

Origin www.cnblogs.com/zhujie-com/p/11696034.html