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?
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