excel - Iterating through items in a PivotTable column -
my loop doesn't work when data field given row , column empty. relevant code follows -
for each pivotitem in pvttbl.rowfields("agent").pivotitems rw = rw + 1 if pvttbl.getpivotdata("prd", "agent", pivotitem.name, "ct1", "ib") = 0 worksheets("sheet1").cells(16, rw).value = 0 else worksheets("sheet1").cells(16, rw).value = pvttbl.getpivotdata("prd", "agent", pivotitem.name, "ct1", "ib") end if next pivotitem the error is:
run-time error 1004/"application-defined or object-defined error"
i've tried "iserror" instead of setting offending line zero, neither works.
that no doubt happens because there combination of pvttbl.getpivotdata("prd", "agent", pivotitem.name, "ct1", "ib") not exist in pivottable. need check see if returns error, , handle accordingly.
that said, seems strange me want via iteration in first place. why not directly check if thing in datafield 0 or not? or why not use getpivotdata formula in worksheet cells concerned?
can elaborate further trying achieve code?
Comments
Post a Comment