I've constructed this code from various sources which copies specified worksheets from a Workbook to a new Workbook using Paste Values. The only element I can't figure out is how to paste the pivot table formats. This is my code:
Sub PasteValues()
Dim ws As Worksheet
Dim wb As Workbook, wbNew As Workbook
With Application
.ScreenUpdating = False
Set wb = ThisWorkbook
wb.Worksheets(Array("Pivot", "Blue", "Green")).Copy
Set wbNew = ActiveWorkbook
For Each ws In ActiveWorkbook.Worksheets
ws.Cells.Copy
ws.[A1].PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
Cells(1, 1).Select
ws.Activate
Next ws
Cells(1, 1).Select
.ScreenUpdating = True
End With
wbNew.SaveAs "C:\Client Jobs\Excel Solutions\My New Workbook.xlsx"
End Sub
I've tried adding the code in red but I can't seem to get it to paste the pivot table format, i.e. Paste Clipboard, can anyone please assist?
Sub PasteValues()
Dim ws As Worksheet
Dim wb As Workbook, wbNew As Workbook
Dim pt As PivotTable
Dim NextRow As Range
Set pt = ActiveSheet.PivotTables(1)
With Application
.ScreenUpdating = False
Set wb = ThisWorkbook
wb.Worksheets(Array("Pivot", "Blue", "Green")).Copy
Set wbNew = ActiveWorkbook
For Each ws In ActiveWorkbook.Worksheets
ws.Cells.Copy
ws.[A1].PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
Cells(1, 1).Select
ws.Activate
Next ws
Cells(1, 1).Select
Set NextRow = ws.Cells(Cells.Rows.Count).End(xlUp).Offset(1)
For Each pt In ws.PivotTables
pt.TableRange2.Copy
Set CurrentRow = NextRow
CurrentRow.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
CurrentRow.Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Next pt
.ScreenUpdating = True
End With
wbNew.SaveAs "C:\Client Jobs\Excel Solutions\My New Workbook.xlsx"
End Sub
Many thanks
Bookmarks