Home » excel » excel vba – how to copy all the fields in a pivot table to other cells in the same sheet

excel vba – how to copy all the fields in a pivot table to other cells in the same sheet

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a user form in excel with a combo box and when I choose something in the combobox it automatically updates a pivot table in a certain sheet.
now I want to take all the fields that are now in the pivot table and copy them to another coulmn. I need to write it in vb but for some reason it wont copy the cells. that is my code:

Set x = ActiveSheet.PivotTables("PivotTable4.1").DataBodyRange.Cells
x.Copy
Application.Goto Reference:="pivot_paste"
x.Paste

everthing works fine except the last line for some reason
please help

How to&Answers:

x.Paste means to copy it to the range x, which is clearly not what you want. Something like this should work:

Set x = ActiveSheet.PivotTables("PivotTable4.1").DataBodyRange.Cells
x.Copy Destination:=ActiveSheet.Range("pivot_paste")