Erreur 1004 : Impossible de lire la propriété PivotFields
Bonjour,
je souhaite créer un tableau croisé de données à partir d'une feuille source , mais lors de la compilation je rencontre un problème : le message d'erreur " erreur 1004 : Impossible de lie la propriété PivotFields de la classe PivotTable " s'affiche. Voici le début du code en question :
Sub TCD_CSVT_APT()
'Dimension des variables
Dim wshTCD As Worksheet
Dim PvtTCD As PivotTable
'Affectation du TCD à la feuille "TCD automatique"
Set wshTCD = Worksheets("TCD automatique")
'Suppression de tous les TCD existants dans la feuille
For Each PvtTCD In wshTCD.PivotTables
PvtTCD.TableRange2.Clear
Next PvtTCD
'Ajout d'un TCD sur la feuille "TCD automatique"
Set PvtTCD = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Tableau3512") _
.CreatePivotTable(tabledestination:=wshTCD.Range("B5"), TableName:="TCD_CSVT_AEROPORT")
'Ajout des champs au TCD
With PvtTCD
'Ajout Lignes
With .PivotFields("RWYCC_Inferieur_PIREP")
.Orientation = xlRowField
.Position = 1
End With
la ligne qui pose problème est " With. PivotFields("RWYCC...) "
Merci de votre aide.
Cdt
RH
Bonjour,
Dans un premier temps, vérifie que le nom du champ existe bien et qu'il est bien orthographié.
Cdlt.
Bonjour,
j'aimerais créer mes propres champs, c'est à dire pour chaque ligne de mon tableau ( position 1,2...) entrer soit RWYCC<PIREP soit RWYCC = PIREP soit RWYCC > PIREP , comme suit :
With .PivotFields("RWYCC_Inferieur_PIREP")
.Orientation = xlRowField
.Position = 1
End With
With .PivotFields("RWYCC_Egal_PIREP")
.Orientation = xlRowField
.Position = 2
End With
With .PivotFields("RWYCC_Superieur_PIREP")
.Orientation = xlRowField
.Position = 3
End With
With .PivotFields("Taux_Csvt")
.Orientation = xlRowField
.Position = 4
End With
With .PivotFields("Nombre_Total_Couples")
.Orientation = xlRowField
.Position = 5
End With
Ce n'est pas possible? merci
cdt
RH
Re,
Le nom du champ doit correspondre à un en-tête de colonne de tes données source.
Pour modifier le nom de l'objet PivotField, tu dois modifier sa propriété Caption.
Un petit fichier avec ce que tu veux faire serait apprécié.
Cdlt.
Re,
je souhaite créer un tableau de 5 lignes et 5 colonnes, chaque colonne correspondant à un aérodrome. Sur la feuille source, tous les aéroports sont listés et des codes "pirep" et "rwycc" sont associés à chacun sous forme de couple. Je souhaite créer un tableau dynamique qui à partir de cette base de données pourra fournir pour chacun des 5 aérodromes le nombre de cas où rwycc>pirep, rwycc=pirep, rwycc<pirep, le nombre total de couples, ainsi que le pourcentage correspondant à Pirep >= rwycc.
Voici mon code dans son entièreté :
Sub TCD_CSVT_APT()
'Dimension des variables
Dim wshTCD As Worksheet
Dim PvtTCD As PivotTable
'Affectation du TCD à la feuille "TCD automatique"
Set wshTCD = Worksheets("TCD automatique")
'Suppression de tous les TCD existants dans la feuille
For Each PvtTCD In wshTCD.PivotTables
PvtTCD.TableRange2.Clear
Next PvtTCD
'Ajout d'un TCD sur la feuille "TCD automatique"
Set PvtTCD = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Tableau3512") _
.CreatePivotTable(tabledestination:=wshTCD.Range("B5"), TableName:="TCD_CSVT_AEROPORT")
'Ajout des champs au TCD
With PvtTCD
'Ajout Lignes
With .PivotFields("[RWYCC]<[PIREP]")
.Orientation = xlRowField
.Position = 1
End With
With .PivotFields("[RWYCC]=[PIREP]")
.Orientation = xlRowField
.Position = 2
End With
With .PivotFields("[RWYCC]>[PIREP]")
.Orientation = xlRowField
.Position = 3
End With
With .PivotFields("Taux_Csvt")
.Orientation = xlRowField
.Position = 4
End With
With .PivotFields("Nombre_Total_Couples")
.Orientation = xlRowField
.Position = 5
End With
'Ajout Colonnes
With .PivotFields("LFST")
.Orientation = xlColumnField
.Position = 1
End With
With .PivotFields("LFPG")
.Orientation = xlColumnField
.Position = 2
End With
With .PivotFields("LFLL")
.Orientation = xlColumnField
.Position = 3
End With
With .PivotFields("LFSB")
.Orientation = xlColumnField
.Position = 4
End With
With .PivotFields("LFRK")
.Orientation = xlColumnField
.Position = 5
End With
'Ajout d'une Valeur nombre
With .PivotFields("Nombre")
.Orientation = xlDataField
End With
End With
End Sub
j'ai trouvé la référence des colonnes rwycc et pirep de la feuille source qui sont [rwycc] et [pirep] , cependant, je n'ai pas de référence pour le nombre total de couple et le pourcentage, je me suis donc dis que je pouvais créer cela moi même et ensuite incrémenter le nombre total de couple à l'aide d'une boucle for dans une fonction, qui se baserait sur la feuille source.
J'espère avoir été clair, le tout n'est pas très évident à saisir.
Cdt,
RH
Re,
Est-il difficile de créer un classeur et de le joindre à ta demande ?
Cdlt.