Re : Pb avec Macro générant un TCD
Alors,
J'ai fait un copier coller de ta macro (qui fonctionne parfaitement dans le fichier que tu m'as joint), qui comporte exactement les même noms que tous les éléments dans ma macro qui ne fonctionnait pas. Alors celà donne :
Sub Testcatrice()
Sheets("Etat Mensuel Par Four").Cells.Clear 'Efface les cellules
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"listing!" & Sheets("listing").Range("A1").CurrentRegion.Address).CreatePivotTable TableDestination:= _
"'[Suivi Global Factures.xls]Etat Mensuel Par Four'!R2C2", TableName:="TCD"
With Sheets("Etat Mensuel Par Four").PivotTables("TCD")
.AddFields RowFields:="Désignation", ColumnFields:="Mois"
With .PivotFields("Prix")
.Orientation = xlDataField
.Caption = "Somme de Prix"
.Function = xlSum
End With
End With
End Sub
Cette manip me donne l'erreur que j'ai cité précedemment. En gras le bug.
Pour contourner le pb j'ai remplacé, dans la macro que j'ai créé, uniquement le code de l'activesheet avec la solution que tu m'as proposé, et là ça fonctionne parfaitement.
Ci dessous le code qui fonctionne (pour lequel j'ai même ajouté un 2ème TCD dans la macro):
Sheets("Etat Mensuel Par Four").Select
ActiveWindow.SmallScroll Down:=-15
Cells.Select
Selection.Delete Shift:=xlUp
Sheets("listing").Select
Range("A1").Select
Selection.CurrentRegion.Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"listing!" & Sheets("listing").Range("A1").CurrentRegion.Address).CreatePivotTable TableDestination:= _
"'[Suvi Global Factures.xls]Etat Mensuel Par Four'!R2C1", TableName:= _
"TCD", DefaultVersion:=xlPivotTableVersion10
With Sheets("Etat Mensuel Par Four").PivotTables("TCD")
.AddFields RowFields:="Désignation", ColumnFields:="Mois"
With .PivotFields("Prix")
.Orientation = xlDataField
.Caption = "Somme de Prix"
.Function = xlSum
End With
End With
Sheets("Etat Par compte").Select
ActiveWindow.SmallScroll Down:=-15
Cells.Select
Selection.Delete Shift:=xlUp
Sheets("listing").Select
Range("A1").Select
Selection.CurrentRegion.Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"listing!" & Sheets("listing").Range("A1").CurrentRegion.Address).CreatePivotTable TableDestination:= _
"'[Suvi Global Factures.xls]Etat Par compte'!R2C1", TableName:= _
"TCD2", DefaultVersion:=xlPivotTableVersion10
With Sheets("Etat Par compte").PivotTables("TCD2")
.AddFields RowFields:="Compte", ColumnFields:="Mois"
With .PivotFields("Prix")
.Orientation = xlDataField
.Caption = "Somme de Prix"
.Function = xlSum
End With
End With
Sheets("listing").Select
Range("A1").Select
End Sub
Donc mon problème est résolu, mais j'aimerais juste comprendre pourquoi le copier coller ne passe pas, tout simplement pour mieux apprendre.
Je te remercie encore une fois de ton aide.
Bonne apres midi
Boune