Avatar of error_prone
error_prone
 asked on

VBA - Filter Pivot Based on Cell Reference - Check For No Values

I have the code below that auto filters a pivot table, "pvtTwo", based on a cell reference.  The cell references another pivot table, ("pvtOne").  So basically selecting a value to filter by in pivot table 1 auto filters for the same value in pivot table 2.
I'm noticing that when the value to filter by in pivot table 1 is not available in the data source of pivot table 2, it writes over the previously selected value in pivot table 2 that was showing.  Is there any way I can amend the code below to not re-label the value in Pivot 2?
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
    On Error Resume Next
    Application.EnableEvents = False
    Me.PivotTables("pvtTwo").PivotFields ("State").CurrentPage = Range("AI7").Value
    Application.EnableEvents = True
End Sub

Open in new window

Microsoft Excel

Avatar of undefined
Last Comment
nutsch

8/22/2022 - Mon
alainbryden

Perhaps you could upload a sample file that demonstrates your problem.
error_prone

ASKER
Here's a sample.  Notice that when you select "Orange" from the pivot on the left, (One), then the other pivot correctly also filters to Orange, (with 120 units).  But if you select "Banana" from pivot One, it renames Orange in pivot Two to Banana, (because Banana does not exist in Two).  I want it to show an empty pivot if the value is not available, (or something like that).  But it should not interfere with the ability to filter in Pivot One.
TEST.xlsm
ASKER CERTIFIED SOLUTION
nutsch

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
error_prone

ASKER
Perfect, thank you!!
Your help has saved me hundreds of hours of internet surfing.
fblack61
nutsch

Glad to help, thanks for the grade.

Thomas