vba - List excel pivot items of the second row field (multiple row fields) given a particular pivot item in the first row field -
i searched long time this, still inconclusive. have pivot table 2 row labels , 1 data variable looking like:
rowlabel1 rowlabel2 sum of value 1 b 2 c 3 d d 4 e e 5
i want able list pivot items of rowlabel2
given particular rowlabel1
, "a"" b" "c"
in loop, concat "abc"
. whatever try, outputs of pivot items, "abcde"
.
since real data more complex, not possible manually. have 3 row labels rather 2 labels.
don't know if solution can make use of values. example, return rowlabel2
items value <= 3
when "letter
" "a"
.
thanks input!!
sub getpiv() dim piv pivottable 'change whatever range , sheet names pivottable set piv = thisworkbook.sheets("secondtable_output").range("a3").pivottable dim r range dim dr pivotitem 'this captures first entry in rowlabel1 - change necessary set dr = piv.pivotfields(1).pivotitems(1) dim str string str = "" 'the macro won't work if item collapsed, set showdetail true expand if dr.showdetail = false dr.showdetail = true end if dr 'address seems bug(??) if there more 1 data value columns, 'the datarange appears shift 1 row down if .datarange.columns.count > 1 'here shift datarange 2nd column of pivottable set r = .datarange.offset(-1, -(.datarange.cells(1, 1).column - 2)) else 'here shift datarange 2nd column of pivottable set r = .datarange.offset(0, -(.datarange.cells(1, 1).column - 2)) end if end 'delete necessary r.select 'obtain string of cell values range = 1 r.rows.count str = str & " " & r.cells(i, 1) next str = trim(str) msgbox str end sub
Comments
Post a Comment