Extract data from Pivot table with VBA

G

gorans

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top