Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50254

Pivot Table issue in VBA

$
0
0
Hi there,

I need help with the following pivot code please. The pivot items "ACC", "FRY", "INS" qnd "OTH" may or may not appear in my range. The problem is that that macro halts if any of the items are not in the range. Is it possible to use an IF instruction to allow for the possibility of the item not being in the range?

Or is there some alternative way to instruct the pivot?

Thanks in advance.

HTML Code:

ActiveSheet.PivotTables("PivotTable8").AddDataField ActiveSheet.PivotTables( _
        "PivotTable8").PivotFields("AGENT COMM EUR"), "Sum of AGENT COMM EUR", xlSum
        ActiveSheet.PivotTables("PivotTable8").AddDataField ActiveSheet.PivotTables( _
        "PivotTable8").PivotFields("TOTAL PRC EUR"), "Sum of TOTAL PRC EUR", xlSum
   
    ActiveSheet.PivotTables("PivotTable8").PivotFields("REC_TYPE").CurrentPage = _
        "(All)"
    With ActiveSheet.PivotTables("PivotTable8").PivotFields("REC_TYPE")
        .PivotItems("ACC").Visible = False
        .PivotItems("FRY").Visible = False
        .PivotItems("INS").Visible = False
        .PivotItems("OTH").Visible = False


Viewing all articles
Browse latest Browse all 50254

Trending Articles