Pivot table filter lock

exo33

New Member
Joined
Oct 29, 2014
Messages
33
Hello All!

I'm encountering issues with the code listed below.
I have a pivot table (Pivot table3) which pulls data from a separate sheet, filters it by field "Liquidate" and lists all parties where liqidation is in effect (value: "y").
Most days there is at least one "y" and everything works as designed then. Problems occur when there there are no liquidations i.e. all fields in "Liquidate" column state "n". In this situation the pivot table filter gets set to "All" (by Excel - not me). Because of this the pivot table displays all parties listed on the source report. Ideally I would like the pivot table to be blank when there are no "y" on the report. Is it possible?


VBA Code:
Sheets("Pivot table3").Select
ActiveSheet.PivotTables("PivotTest3").PivotCache.Refresh

ActiveSheet.PivotTables("PivotTest3").PivotFields("Liquidate").ClearAllFilters '----> this section was meant to prevent errors when there are no Liquidate boxes checked
ActiveSheet.PivotTables("PivotTest3").PivotFields("Liquidate").CurrentPage = _
        "y"
On Error Resume Next
    lastRow = Range("A" & Rows.Count).End(xlUp).Row
    If lastRow > 6 Then ' new code
    Range("C6").AutoFill Destination:=Range("C6:C" & lastRow)
    Range("D6").AutoFill Destination:=Range("D6:D" & lastRow)
    End If ' new code
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hello All!

I'm encountering issues with the code listed below.
I have a pivot table (Pivot table3) which pulls data from a separate sheet, filters it by field "Liquidate" and lists all parties where liqidation is in effect (value: "y").
Most days there is at least one "y" and everything works as designed then. Problems occur when there there are no liquidations i.e. all fields in "Liquidate" column state "n". In this situation the pivot table filter gets set to "All" (by Excel - not me). Because of this the pivot table displays all parties listed on the source report. Ideally I would like the pivot table to be blank when there are no "y" on the report. Is it possible?


VBA Code:
Sheets("Pivot table3").Select
ActiveSheet.PivotTables("PivotTest3").PivotCache.Refresh

ActiveSheet.PivotTables("PivotTest3").PivotFields("Liquidate").ClearAllFilters '----> this section was meant to prevent errors when there are no Liquidate boxes checked
ActiveSheet.PivotTables("PivotTest3").PivotFields("Liquidate").CurrentPage = _
        "y"
On Error Resume Next
    lastRow = Range("A" & Rows.Count).End(xlUp).Row
    If lastRow > 6 Then ' new code
    Range("C6").AutoFill Destination:=Range("C6:C" & lastRow)
    Range("D6").AutoFill Destination:=Range("D6:D" & lastRow)
    End If ' new code
Bump. Anyone has any ideas? Thanks in advance for any suggestions!
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,638
Members
449,093
Latest member
Ahmad123098

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