Macro filter field, if field is not present, skip filter

txdude311

New Member
Joined
Jul 26, 2016
Messages
5
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
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,215,596
Messages
6,125,726
Members
449,255
Latest member
whatdoido

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top