VBA Excel macro création de TCD
Résolu
pzyko
Messages postés
34
Date d'inscription
Statut
Membre
Dernière intervention
-
pzyko Messages postés 34 Date d'inscription Statut Membre Dernière intervention -
pzyko Messages postés 34 Date d'inscription Statut Membre Dernière intervention -
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
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:
- VBA Excel macro création de TCD
- Telecharger macro convertir chiffre en lettre excel - Télécharger - Tableur
- Tcd excel - Guide
- Liste déroulante excel - Guide
- Word et excel gratuit - Guide
- Creation de compte google - Guide