Sub a()
With Workbooks.ADD
.Sheets(1).Name = "TDC"
TdcExistant(ThisWorkbook.Sheets("Tdc"), "TDC").TableRange2.Copy .Sheets("TDC").Range("A1")
.Sheets("TDC").PivotTables(.Sheets("TDC").PivotTables.Count).Name = "TDC"
ThisWorkbook.Sheets("Data").UsedRange.Copy .Sheets("Feuil3").Range("A1")
.Sheets("TDC").PivotTables("TDC").PivotCache.SourceData = "Feuil3!" & Range("G1:K7").Address(ReferenceStyle:=xlR1C1)
End With
End Sub
Public Function TdcExistant(Sh As Worksheet, Tdc As String) As PivotTable
For Each td In Sh.PivotTables
If UCase(td.Name) = UCase(Tdc) Then
Set TdcExistant = td
Exit For
End If
Next
End Function