Hello,I have a MACRO that needs to filter out certain fields. However, the data won't always contain these fields. When these fields aren't present the macro errors out.
How can the macro filter out these fields when they are present and just skip this command when they are not present.
Perhaps I need an "if/and" function but I don't know how to create it here.
Macro 5, if the pivot table contains the below fields, filter out, if not skip and continue the macro:
* "blanks" (i.e. "")
* Invoice Cash Credit XFer (+)
* Invoice Cash Debit XFer (-)
* Invoice Non-Cash Credit XFer (+)
* Invoice Non-Cash Debit XFer (-)
Macro 6, if the pivot table contains the below fields, filter out, if not skip and continue the macro:
* AF35
------------------------- VBA code is as follows-------------------------:
Sub Macro5()
'
' Macro5 Macro
'
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Check / Trace #")
.PivotItems("").Visible = False
.PivotItems("Invoice Cash Credit XFer (+)").Visible = False
.PivotItems("Invoice Cash Debit XFer (-)").Visible = False
.PivotItems("Invoice Non-Cash Credit XFer (+)").Visible = False
.PivotItems("Invoice Non-Cash Debit XFer (-)").Visible = False
End With
End Sub
Sub Macro6()
'
' Macro6 Macro
'
ActiveSheet.PivotTables("PivotTable1").PivotFields("Financial Code"). _
CurrentPage = "(All)"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Financial Code")
.PivotItems("AF35").Visible = False
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("Financial Code"). _
EnableMultiplePageItems = True
End Sub
How can the macro filter out these fields when they are present and just skip this command when they are not present.
Perhaps I need an "if/and" function but I don't know how to create it here.
Macro 5, if the pivot table contains the below fields, filter out, if not skip and continue the macro:
* "blanks" (i.e. "")
* Invoice Cash Credit XFer (+)
* Invoice Cash Debit XFer (-)
* Invoice Non-Cash Credit XFer (+)
* Invoice Non-Cash Debit XFer (-)
Macro 6, if the pivot table contains the below fields, filter out, if not skip and continue the macro:
* AF35
------------------------- VBA code is as follows-------------------------:
Sub Macro5()
'
' Macro5 Macro
'
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Check / Trace #")
.PivotItems("").Visible = False
.PivotItems("Invoice Cash Credit XFer (+)").Visible = False
.PivotItems("Invoice Cash Debit XFer (-)").Visible = False
.PivotItems("Invoice Non-Cash Credit XFer (+)").Visible = False
.PivotItems("Invoice Non-Cash Debit XFer (-)").Visible = False
End With
End Sub
Sub Macro6()
'
' Macro6 Macro
'
ActiveSheet.PivotTables("PivotTable1").PivotFields("Financial Code"). _
CurrentPage = "(All)"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Financial Code")
.PivotItems("AF35").Visible = False
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("Financial Code"). _
EnableMultiplePageItems = True
End Sub