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.

:warning: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.:warning:


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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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