Copy and Paste From Pivot Tables Into New Workbook

icekiwikiwi

New Member
Joined
Oct 20, 2021
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Hi everyone

I have a workbook with the same pivot table filtered around 25 different ways, each on a separate tab. I need to copy and paste it to a new document without the pivot tables, but still retaining the formatting.

I have butchered together the following code (which works) but I feel like there are probably a number of redundancies here. The code itself takes a few minutes to run so its quite resource intensive.

Any suggestions to streamline my code are appreciated! Thank you.

VBA Code:
Sub Duplicate_Workbook

Dim Sh As Worksheet

Application.ScreenUpdating = False
Application.Cursor = xlWait


ActiveWorkbook.Sheets.Copy

     For Each Sh In ActiveWorkbook.Worksheets
        If Sh.Visible = True Then
            Sh.Activate
            Sh.Cells.Copy
            Sh.Range("A1").PasteSpecial Paste:=xlPasteValues
            Sh.Activate
            Sh.Cells.Copy
            Sh.Range("A1").PasteSpecial Paste:=xlPasteFormats
            Sh.Range("A1").Select
        End If
    Next Sh
    
Application.CutCopyMode = False

Application.ScreenUpdating = True
Application.Cursor = xlDefault

End Sub
 
I can give you code that will copy the actual pivot table formatting if you want it.
This code will reset the selected cell in the copied workbook.

VBA Code:
Sub RepositionActiveCell()
   
    Dim ws As Worksheet
    For Each ws In Worksheets
        ws.Activate
        ws.Range("A1").Select
       
    Next ws  

End Sub
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Now I just need to work out how to make sure each tab is unselected after being copied and pasted. It's currently left highlighted in the new document.
I like to use the GoTo method:

VBA Code:
Call Application.Goto(Reference:=.Range("A1"),Scroll:=True)
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

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