getpivotdata and row total

djsmarties

Board Regular
Joined
Sep 10, 2002
Messages
95
Hi,

i have a question regarding "getpivotdata".

I have a pivot table which looks like this:

count of record days
employee 1-3days 4-6 days 5-7 days grand total
xxx1
xxx2
xxx3

The pivot is refreshed daily and the data for both the row (different employees every day) and the column change depending on the raw data (number of columns changes between 2-6). What i want to do is copy the grand total column out of the pivot table using a macro so i can use it for further calculations . Can I use getpivotdata to get the grand total from each row? And if yes, how?


thanks
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
This will copy the row totals to A1 on Sheet2:

Code:
Sub Test()
    With Worksheets("Sheet1").PivotTables(1).DataBodyRange
        .Columns(.Columns.Count).Copy Worksheets("Sheet2").Range("A1")
    End With
End Sub
 

djsmarties

Board Regular
Joined
Sep 10, 2002
Messages
95
Thanks Andrew,

i modified the code to match my data:
Sub copytest()
With Worksheets("pivot").PivotTables(2).DataBodyRange
.Columns(.Columns.Count).Copy Worksheets("test").Range("A1")
End With
End Sub

But i get an error: "Unable to get the PIvotTable property of the Worksheet class"

Am I doing something wrong here? I just copied the code into a macro and then run the macro?
 

djsmarties

Board Regular
Joined
Sep 10, 2002
Messages
95
Ah, I thought "PivotTables(1)." is the name of the pivot table.... right, changed it back to 1 and now it works perfectly :)

Thanks a lot
 

Forum statistics

Threads
1,141,019
Messages
5,703,774
Members
421,315
Latest member
awaisnazir139

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
Top