ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Extract data from Pivot table with VBA (https://www.excelbanter.com/excel-programming/381778-extract-data-pivot-table-vba.html)

[email protected]

Extract data from Pivot table with VBA
 
Hi,

I am attempting to extract a 'copy' of a pivot table I have
automatically generated into another worksheet. However, I would like
to modify the formatting of it slightly.

I have come accross some fairly novel ways to do this but they will not
work for me because the pivot table is genereated from dynamic data.
Hence the size and values will constantly be changing. Although, the
actual field names will remain constant.

The pivot table produces something like this:
__________________________________________________ _
.......................................*Company
*Class.......|....*attrib......|.C1...|.C2..|.C3.. |
..............|.................|......|.....|.... .|
Employee.....|..name...........|...1..|..1..|..0.. |
..............|..surname........|...1..|..1..|..0. .|
Document.....|..title..........|...1..|..0..|..1.. |
..............|..id.............|...0..|..1..|..1. .|
__________________________________________________ _

and I want to get:
__________________________________________________ _
.......................................*Company
*Class.......|...*attrib.......|.C1..|.C2..|.C3..|
..............|.................|.....|.....|..... |
Employee.......................|..2..|..2..|..1..|
..............|..name...........|..1..|..1..|..0.. |
..............|..surname........|..1..|..1..|..0.. |
Document.......................|..1..|..1..|..2..|
..............|..title..........|...1.|..0..|..1.. |
..............|..id.............|..0..|..1..|..1.. |
__________________________________________________ _
Note: Copy and past the table into a text editor such as notepad to
view properly

Does anyone have any hints or tips as to how i can approach this task.

I was thinking to nest some for loops

for pivot_item in ptable.pivotfields('class').pivotitems
for ...

but having inspected all the properties of pivot items, pivot fields
and pivot cells i cannot find some sort of correlation between class
and attribute (the correlation i want is that class should group
attributes)

If i then have each class-attribute pair, i will be able to get the
data i need using getpivotdata or similar.

Any help is greately appreciated.

Kind Regards

Goran



All times are GMT +1. The time now is 12:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com