VBA Copy/Paste & Transpose Specific Columns from PivotTable to Table

rach_oh

New Member
Joined
Aug 2, 2023
Messages
19
Office Version
  1. 2016
Platform
  1. Windows
Trying to take four pivot tables and copy specific columns from each into its own row in a table on a new sheet. I'm spinning in circles. So far, this is what I have below

For each row in each pivot table, I need the macro to copy the "rngList" and transpose on the table in column E creating 12 new rows. On each of the new rows, Field Names [Accounting Structure], [Dimension Values], [Amount Type] from the PivotTable needs to be copied over to the table in columns F, G, & J respectively. Then each new row needs the data copied over from each of the 12 Value Columns "Sum of MMM-24". Once one row in pivot table is copied, it needs to go through the rest of that pivot table and then complete the same actions for the other three pivot tables.

Examples of PivotTables to be copied and the Table data will be pasted into below as well.


VBA Code:
Private Sub CommandButton8_Click()
Dim tbl As ListObject
Set tbl = Worksheets("Dynamics Budget Upload").ListObjects("DynamicsBudgetUpload")

Dim GPT As PivotTable, MaintPT As PivotTable, FBPT As PivotTable, GAPT As PivotTable
Set GPT = Worksheets("GPivot").PivotTable("GPivot")
Set MaintPT = Worksheets("Maintenance Pivot").PivotTable("Maintenance Pivot")
Set FBPT = Worksheets("F&B Pivot").PivotTable("F&B Pivot")
Set GAPT = Worksheets("G&A Pivot").PivotTable("G&A Pivot")

GPT.RowAxisLayout xlTabularRow
MaintPT.RowAxisLayout xlTabularRow
FBPT.RowAxisLayout xlTabularRow
GAPT.RowAxisLayout xlTabularRow

Dim rngList As Range
Set rngList = Worksheets("GPivot").Range("D5:O5")


On Error GoTo ErrorMessage
With GPT

With tbl

ErrorMessage:
    MsgBox "An error has occurred: " & Err.Description
    Resume ExitSub

End Sub

1692394663661.png


1692394870609.png
 
Last edited by a moderator:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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