VBA - Autofilter stops when criteria is missing

auggie24

New Member
Joined
Sep 11, 2018
Messages
7
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi all, newish to VBA, but picking up quickly. Sometimes the value in the filter is not in the data, and causes my vba to bug out on me. I commented it out, but would like to write something that would allow the code to finish by ignoring the criteria if it is unavailable.

PHP:
With ActiveSheet.PivotTables("PivotTable5").PivotFields("SD Delivery Block")
'        .PivotItems("89").Visible = False                       commented out due to failure
'        .PivotItems("91").Visible = False
'        .PivotItems("92").Visible = False
'        .PivotItems("93").Visible = False
'        .PivotItems("94").Visible = False
'        .PivotItems("95").Visible = False
'        .PivotItems("97").Visible = False
'        .PivotItems("CR").Visible = False
'        .PivotItems("(blank)").Visible = False
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
(Untested with PivotItems but it usually does the job with most things :) ) Try inserting this line immediately above With ActiveSheet...
Code:
On Error Resume Next
and inserting this immediately below End With
Code:
On Error GoTo 0

VBA ignores all errors in between the 2 statements. The 2nd statement resets things ensuring that further errors are highlighted.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,023
Latest member
alabaz

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