Karthik Thandapani
Member
Hi,
I am working on a dashboard requires fresh pivot & slicers every single day. Can anyone please suggest an idea how to clear/delete existing slicers along with pivot table?
P.S: presently the below code only clears the pivot but not its slicers.
Thanks,
Karthik
I am working on a dashboard requires fresh pivot & slicers every single day. Can anyone please suggest an idea how to clear/delete existing slicers along with pivot table?
P.S: presently the below code only clears the pivot but not its slicers.
Code:
Dim WB As Workbook, ws As Worksheet, pt As PivotTable
If ActiveWorkbook Is Nothing Then
MsgBox "There is no active workbook!", vbExclamation, "ERROR!"
Exit Sub
End If
If MsgBox("Delete ALL pivot tables in the active workbook?", _
vbYesNo + vbDefaultButton2, "DELETE ALL?") = vbNo Then Exit Sub
On Error Resume Next
For Each ws In ActiveWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.TableRange2.Clear
'WS.Range(PT.TableRange2.Address).Delete Shift:=xlUp
Next pt
Next ws
Karthik