Macro not re-creating my pivot table

blair878

New Member
Joined
Jul 13, 2012
Messages
2
Good morning / afternoon everyone. I have a macro that is not completing the pivots which were recorded. This happens with not only deleting the pivot information but also creating a new table.:confused:

I'm not sure if anyone know a good solution for this as I have tried several times to record pivot table creation and it is not working.

:eek:I've inserted my issue below but as a warning, there are 3 pivot tables which need to be created and I'm not a VBA pro.:eek:


ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"CORE Recon Refi!R1C1:R250C8", Version:=xlPivotTableVersion12). _
CreatePivotTable TableDestination:="Daily Summary!R5C4", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion12


Thanks!!

TB
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try replacing...

Code:
TableDestination:="Daily Summary!R5C4"

with

Code:
TableDestination:=wksDest.Range("D5")

Here's another way...

Code:
Option Explicit
Sub test()
    Dim wksSource As Worksheet
    Dim wksDest As Worksheet
    Dim PTCache As PivotCache
    Dim PT As PivotTable
    
    Set wksSource = Worksheets("CORE Recon Refi")
    
    Set wksDest = Worksheets("Daily Summary")
    
    Set PTCache = ActiveWorkbook.PivotCaches.Create( _
        SourceType:=xlDatabase, _
        SourceData:=wksSource.Range("A1").CurrentRegion, _
        Version:=xlPivotTableVersion12)
        
    Set PT = wksDest.PivotTables.Add( _
        PivotCache:=PTCache, _
        TableDestination:=wksDest.Range("D5"), _
        TableName:="PivotTable1", _
        DefaultVersion:=xlPivotTableVersion12)
        
    [COLOR=#008000]'optional (change the pivot field names, property settings, etc, accordingly)[/COLOR]
    With PT
        .PivotFields("PivotField1").Orientation = xlRowField
        .PivotFields("PivotField2").Orientation = xlColumnField
        .PivotFields("Pivotfield3").Orientation = xlDataField
        .DataBodyRange.NumberFormat = "#,##0"
        .TableStyle2 = "PivotStyleMedium2"
        .DisplayFieldCaptions = False
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,596
Messages
6,120,438
Members
448,966
Latest member
DannyC96

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