Forum Discussion
Brian Catalano
Feb 16, 2018Copper Contributor
Pasting Pivot Table as Values... losing Borders and formatting
This just started within the last 30 days or so... it appears that when pasting a Pivot Table as values over itself... borders and formatting are now eliminated. Extremely frustrating as I have the ...
- Feb 17, 2018
Hi Brian,
There is a fairly good technique to paste the PivotTable values and formats, but it cost you some extra steps!
You can use the Format Painter to grab the format to the second instance of the PivotTable.
After you paste the PivotTable as values, go to the original PivotTable, highlight it, press Format Painter button, and then paint the second PivotTable!
Another method (Two levels Paste):
- Highlight the first PivotTable and copy it.
- Go to another location, and press Ctrl+Alt+V to open the Paste Special dialog box.
- Select Values and then hit OK.
- Press Ctrl+Alt+V again.
- Select Formats and then hit OK again!
Subodh_Tiwari_sktneer
Aug 18, 2019Silver Contributor
If you want to copy the Pivot Table and paste it over itself as values along with formatting, you can try something like this...
Sub CopyPivotTableAndPasteBackAsValuesAndFormatting()
Dim ws As Worksheet
Dim pt As PivotTable
Dim lc As Long, r As Long, c As Long
Dim pstRng As Range, tmpRng As Range, tmpRng2 As Range
Dim ptRng1 As Range, ptRng2 As Range
Set ws = ActiveSheet
lc = ws.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 2
If ws.PivotTables.Count = 0 Then Exit Sub
Set pt = ws.PivotTables(1)
Set pstRng = pt.TableRange2.Cells(1)
r = pt.TableRange2.Rows.Count
c = pt.TableRange2.Columns.Count
Set tmpRng = ws.Cells(1, lc)
Set tmpRng2 = ws.Cells(3, lc)
Set ptRng1 = pt.TableRange1
Set ptRng2 = pt.TableRange2
MsgBox ptRng1.Address
MsgBox ptRng2.Address
If ptRng1.Address <> ptRng2.Address Then
pt.TableRange2.Cells(1).CurrentRegion.Copy
tmpRng.PasteSpecial xlPasteValues
tmpRng.PasteSpecial xlPasteFormats
pt.TableRange1.Copy
tmpRng2.PasteSpecial xlPasteValuesAndNumberFormats
tmpRng2.PasteSpecial xlPasteFormats
Else
pt.TableRange1.Copy
tmpRng.PasteSpecial xlPasteValuesAndNumberFormats
tmpRng.PasteSpecial xlPasteFormats
End If
pt.TableRange2.Clear
tmpRng.Resize(r, c).Copy pstRng
tmpRng.Resize(r, c).Clear
End Sub
Hope this helps.