View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T[_7_] Peter T[_7_] is offline
external usenet poster
 
Posts: 162
Default Pivot table - VB code


"TheExpat Wanderer" wrote in message
please help me,
I cant attach files to clarify the issue

is there a way to list pivot table data to a normal sheet rows and columns

this is my daily work it took me 1 hour to finish it , but I think with a
VB code it could be done on 1 minute.

I don't know if this could be done by formula.
please reply to me for any clarification.


If you mean copy the entire PT as displayed including labels

Sub test()
Dim pt As PivotTable
Dim wsSource As Worksheet
Dim wsTarget As Worksheet

Set wsSource = Worksheets("Sheet1") ' < change
Set wsTarget = Worksheets("Sheet2") ' < change

Set pt = wsSource.PivotTables(1)

pt.TableRange2.Copy

With wsTarget.Range("A1")
.PasteSpecial xlPasteValues
' following are optional
.PasteSpecial xlPasteColumnWidths
.PasteSpecial xlPasteFormats
End With

End Sub

Regards,
Peter T

If either sheet might not be in the active workbook qualify as necessary, eg

Set ws = Worbooks("filename").Worksheets("Sheetname")

Regards,
Peter T