Copy Sheet to New Workbook & Flatten Pivot Tables

JADownie

Active Member
Joined
Dec 11, 2007
Messages
395
Hello -

I use the below code to copy my current worksheet to a new workbook. That works fine.

I wanted to use this in another file now, but that file has Pivot Tables on the sheet. Is there an easy way to update this code to include flattening any Pivot Tables on the sheet?

Thanks for any guidance!!


Sub Copy_to_New_WB()
Sheets("Summary").Copy
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Once the Pivot Table is in the new workbook, and for example if the table is Date and Sales, have Date in Rows, Sum of Sales in Column and the Grand Total showing, then double click the Grand Total item and a new Worksheet will be created with ALL of the details of the original data.

I recorded selecting the Grand Total cell in a Pivot Table and then double clicking it, and this is the code that resulted:
VBA Code:
Sub Macro1()
'
' Macro1 Macro
'

'
    Range("B68").Select
    Selection.ShowDetail = True
End Sub
Cell B68 held the Grand Total of about 65 rows of annual data grouped by year of 772 rows of monthly data. Double clicking restored all 772 rows of data. And yes, I only did this with 2 columns of data, but all data will come through as it's all in the Pivot Cache.
 
Upvote 0

Forum statistics

Threads
1,215,427
Messages
6,124,831
Members
449,190
Latest member
rscraig11

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