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
 

Some videos you may like

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

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
Bump. Anyone has any ideas? Thanks in advance for any suggestions!
 

Watch MrExcel Video

Forum statistics

Threads
1,118,279
Messages
5,571,288
Members
412,375
Latest member
BRJoeyMelo
Top