VBA Excel macro création de TCD

Résolu/Fermé
pzyko Messages postés 34 Date d'inscription vendredi 27 juin 2014 Statut Membre Dernière intervention 8 août 2014 - 30 juin 2014 à 10:27
pzyko Messages postés 34 Date d'inscription vendredi 27 juin 2014 Statut Membre Dernière intervention 8 août 2014 - 30 juin 2014 à 11:43
Bonjour,

Novice en VBA, je dois créer une macro générant 3 TCD en fonction de données contenues dans un tableau. J'ai créé la macro ci-dessous. Toutefois, lorsque je la lance, seul le dernier des 3 TCD vient se créer. Quelqu'un peut-il me donner une solution pour que les 3 apparaissent en même temps?

Sub creapivot()

Dim derLigneK As Long
Dim derLigneE As Long
Dim derLigneI As Long
Dim plageX As Range
Dim plageY As Range
Dim plageZ As Range

With Sheets("Feuil1")
derLigneE = .Range("E" & .Rows.Count).End(xlUp).Row
End With

With Sheets("Invisible")
derLigneK = .Range("K" & .Rows.Count).End(xlUp).Row
derLigneI = .Range("I" & .Rows.Count).End(xlUp).Row
End With

Set plageX = Sheets("Feuil1").Range("E1:E" & derLigneE)
Set plageY = Sheets("Invisible").Range("K1:K" & derLigneK)
Set plageZ = Sheets("Invisible").Range("A1:H" & derLigneI)

ActiveSheet.PivotTableWizard _
SourceType:=xlDatabase, _
SourceData:=plageX, _
TableDestination:=Sheets("TCD").Range("A3"), _
TableName:="TCD1"

With ActiveSheet.PivotTables("TCD1")
.AddFields RowFields:="Type"
.PivotFields("Type").Orientation = xlDataField

End With

ActiveSheet.PivotTableWizard _
SourceType:=xlDatabase, _
SourceData:=plageY, _
TableDestination:=Sheets("TCD").Range("A12"), _
TableName:="TCD2"

With ActiveSheet.PivotTables("TCD2")
.AddFields RowFields:="Univers campagne"
.PivotFields("Univers campagne").Orientation = xlDataField

End With

ActiveSheet.PivotTableWizard _
SourceType:=xlDatabase, _
SourceData:=plageZ, _
TableDestination:=Sheets("TCD").Range("A30"), _
TableName:="TCD3"

With ActiveSheet.PivotTables("TCD3")

.PivotFields("AAAA").Orientation = xlDataField
.PivotFields("BBBB").Orientation = xlDataField
.PivotFields("CCCC").Orientation = xlDataField
.PivotFields("DDDD").Orientation = xlDataField
.PivotFields("EEEE").Orientation = xlDataField
.PivotFields("FFFF").Orientation = xlDataField
.PivotFields("GGGG").Orientation = xlDataField
.PivotFields("HHHH").Orientation = xlDataField

End With

End Sub
A voir également:

1 réponse

pzyko Messages postés 34 Date d'inscription vendredi 27 juin 2014 Statut Membre Dernière intervention 8 août 2014 1
30 juin 2014 à 11:43
J'ai trouvé seul, il fallait nommer les feuilles plutot que d'utiliser activesheet
1