impossible de créer un deuxième tableau croisé par macro

mumu

XLDnaute Occasionnel
Bonjour,

Après un petit tour dans le forum sans réponse à mon problème, j'ose quémander de l'aide ....
J'essaie de créer deux tableaux croisés dynamiques provenant de la même source mais n'ayant pas la même forme finale.
Tout marchait super bien jusqu'à présent et maintenant j'ai un message d'erreur au tout début de la création du second tableau croisé. Je n'y comprends rien. C'est au niveau de la ligne Activeworbook[...] que ça plante (appel de procédure incorrect). J'ai redémarré excel, le PC puis re excel.... Bref je ne sais pas ce qui se passe.
Voici le code créé en grande partie par l'enregistreur

Code:
[.....]
DerLig26 = Sheets("Total").Range("A" & Rows.Count).End(xlUp).Row
Sheets("Total").Select
Sheets("Total").Range("A1:D" & DerLig26).Select
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Total!R1C1:R" & DerLig26 & "C4", Version:=xlPivotTableVersion10).CreatePivotTable TableDestination:="Récap!R3C1", TableName:="TCD", _
        DefaultVersion:=xlPivotTableVersion10
    Sheets("Récap").Select
    Cells(3, 1).Select
    ActiveWorkbook.ShowPivotTableFieldList = True
    With Sheets("Récap").PivotTables("TCD").PivotFields("projet")
        .Orientation = xlRowField
        .Position = 1
    End With
    With Sheets("Récap").PivotTables("TCD").PivotFields("phase")
        .Orientation = xlRowField
        .Position = 2
    End With
        With Sheets("Récap").PivotTables("TCD").PivotFields("mois")
        .Orientation = xlColumnField
        .Position = 1
    End With

    Sheets("Récap").PivotTables("TCD").AddDataField ActiveSheet.PivotTables("TCD").PivotFields("Total (H)"), "Somme de Total (H)", xlSum
    
Sheets.Add.Name = "Report année en cours"

'2 eme tableau croisé dynamique

Sheets("Total").Select
Sheets("Total").Range("A1:D" & DerLig26).Select
   
     ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Total!R1C1:R" & DerLig26 & "C4", Version:=xlPivotTableVersion10).CreatePivotTable _ 
TableDestination:="Report année en cours!R3C1", TableName:="TCD1", _
      DefaultVersion:=xlPivotTableVersion10
    Sheets("Report année en cours").Select
    Cells(3, 1).Select
    ActiveWorkbook.ShowPivotTableFieldList = True
    With Sheets("Report année en cours").PivotTables("TCD1").PivotFields("projet")
        .Orientation = xlRowField
        .Position = 1
    End With
    With Sheets("Report année en cours").PivotTables("TCD1").PivotFields("phase")
        .Orientation = xlRowField
        .Position = 2
    End With
  Sheets("Report année en cours").PivotTables("TCD1").AddDataField ActiveSheet.PivotTables("TCD1").PivotFields("Total (H)"), "Somme de Total (H)", xlSum
[.....]

Merci pour votre aide.
A +
Mumu
 

Zon

XLDnaute Impliqué
Re : impossible de créer un deuxième tableau croisé par macro

Salut,

à première vue la feuille Report année en cours existe-t elle toujours ?


sinon tu peux me contacter par messagerie privée pour me donner ton mail ..

A+++
 

Discussions similaires

Réponses
1
Affichages
1 K
Compte Supprimé 979
C

Statistiques des forums

Discussions
312 103
Messages
2 085 319
Membres
102 862
dernier inscrit
Emma35400