Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unfortunately, there appears to be no way to directly manipulate PivotCache in Excel.</p> <p>I did find a work around. The following code extracts the the pivot cache for every pivot table found in a workbook, puts it into a new pivot table and creates only one pivot field (to ensure that all rows from the pivot cache are incorporated in the total), and then fires ShowDetail, which creates a new sheet with all of the pivot table's data in.</p> <p>I would still like to find a way to work directly with PivotCache but this gets the job done.</p> <pre><code>Public Sub ExtractPivotTableData() Dim objActiveBook As Workbook Dim objSheet As Worksheet Dim objPivotTable As PivotTable Dim objTempSheet As Worksheet Dim objTempPivot As PivotTable If TypeName(Application.Selection) &lt;&gt; "Range" Then Beep Exit Sub ElseIf WorksheetFunction.CountA(Cells) = 0 Then Beep Exit Sub Else Set objActiveBook = ActiveWorkbook End If With Application .ScreenUpdating = False .DisplayAlerts = False End With For Each objSheet In objActiveBook.Sheets For Each objPivotTable In objSheet.PivotTables With objActiveBook.Sheets.Add(, objSheet) With objPivotTable.PivotCache.CreatePivotTable(.Range("A1")) .AddDataField .PivotFields(1) End With .Range("B2").ShowDetail = True objActiveBook.Sheets(.Index - 1).Name = "SOURCE DATA FOR SHEET " &amp; objSheet.Index objActiveBook.Sheets(.Index - 1).Tab.Color = 255 .Delete End With Next Next With Application .ScreenUpdating = True .DisplayAlerts = True End With End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload