In my macro, all of my pivot tables were able to generate but one. How can I fix this?

randombubble3

New Member
Joined
Mar 15, 2021
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
I changed the code using the answer I saw here that helped generate the 2 out of 3 of my pivot tables, but the last one isn't generating. Any tips on how to get the last pivot table to work? Every time I try to run the code, it says I need to debug it.

First 2 codes that worked are below, and the bottom 2 are the code variations for that pivot table that did not work. (View as separate and not connected together)
VBA Code:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Sheet1!R1C1:R234C33", Version:=6).CreatePivotTable TableDestination:=Worksheets("3. Summary").Range("A1"), TableName:="PivotTable6", DefaultVersion:=6

ActiveWorkbook.Worksheets("3. Summary").PivotTables("PivotTable6"). _
        PivotCache.CreatePivotTable TableDestination:=Worksheets("4. Summary1").Range("A1"), TableName:="PivotTable7", DefaultVersion _
        :=6

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Sheet1!R1C1:R234C33", Version:=6).CreatePivotTable TableDestination:=Worksheets("5. Summary2").Range("A1"), TableName:="PivotTable8", DefaultVersion:=6

ActiveWorkbook.Worksheets("3. Summary").PivotTables("PivotTable6"). _
        PivotCache.CreatePivotTable TableDestination:=Worksheets("5. Summary2").Range("A1"), TableName:="PivotTable8", DefaultVersion _
        :=6
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Alex Blakenburg

Well-known Member
Joined
Feb 23, 2021
Messages
606
Office Version
  1. 365
Platform
  1. Windows
Based on what I am seeing you should be getting 3 Pivot tables and its the 4th that is crashing.
The 4th is crashing because it has the same TableDestination as the 3rd.
Both 3 & 4 have l=the ine:-
TableDestination:=Worksheets("5. Summary2").Range("A1")
I changed this to:
TableDestination:=Worksheets("6. Summary3").Range("A1")
and it worked fine.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,072
Messages
5,639,916
Members
417,118
Latest member
warranty123

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
Top