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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
(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,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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