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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
(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,215,463
Messages
6,124,965
Members
449,201
Latest member
Jamil ahmed

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