Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata
Sub Test()
PTableExists = ExistPivot("PTableName")
If PTableExists = True Then
'MsgBox "Deleting PTable!"
 Call DeletePivotTable("PTableName", "PivotTableSheet")
End If
End Sub
Public Function ExistPivot(ptName As String) As Boolean
Dim WS As Worksheet, PT As PivotTable

    ExistPivot = False
    For Each WS In ActiveWorkbook.Worksheets
        For Each PT In WS.PivotTables
            If PT.Name = ptName Then
                ExistPivot = True
                Exit Function
            End If
        Next PT
    Next WS
End Function
Sub DeletePivotTable(ptName As String, SheetName As String)
Dim WB As Workbook, WS As Worksheet, PT As PivotTable

Set WB = ThisWorkbook
Set WS = WB.Worksheets(SheetName)
Set PT = WS.PivotTables(ptName)


End Sub
  • No labels