在此,并非所有时间,当我提取报告时,我将选择12L或03A。如何应用if语句,只有当这些选项可用时才会过滤(取消选择)。
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Purchasing Group")
.Orientation = xlPageField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("Item").CurrentPage = "10"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Purchasing Group"). _
CurrentPage = "(All)"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Purchasing Group")
.PivotItems("03A").Visible = False
.PivotItems("12L").Visible = False
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("Purchasing Group"). _
EnableMultiplePageItems = True
Range("A7").Select
ActiveSheet.PivotTables("PivotTable1").InnerDetail = "Contract"
Selection.ShowDetail = True
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
End Sub
答案 0 :(得分:0)
我假设这个
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Purchasing Group")
.PivotItems("03A").Visible = False
.PivotItems("12L").Visible = False
End With
当" 03A" 生成错误和" 12L"不可用。您只需添加On Error Resume Next
。
On Error Resume Next 'In case of error, go to next line
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Purchasing Group")
.PivotItems("03A").Visible = False
.PivotItems("12L").Visible = False
End With
On Error GoTo 0 'Disable any enabled error handler