Bonjour,

Je souhaite automatiser la mise en place d'un tableau croisé dynamique avec une Macro, j'ai pour habitude d'utiliser la fonction enregistrer une Macro pour avoir le gros du code avant de le décortiquer, mais pour le coup je sèche, il y a trop d'inconnus pour moi dans ce type de code .

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Sub Macro2()
'
' Macro2 Macro
'
 
'
    Application.CutCopyMode = False
    Sheets.Add
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "ventes aout!R1C1:R94C5", Version:=8).CreatePivotTable TableDestination:= _
        "Feuil2!R3C1", TableName:="Tableau croisé dynamique2", DefaultVersion:=8
    Sheets("Feuil2").Select
    Cells(3, 1).Select
    With ActiveSheet.PivotTables("Tableau croisé dynamique2")
        .ColumnGrand = True
        .HasAutoFormat = True
        .DisplayErrorString = False
        .DisplayNullString = True
        .EnableDrilldown = True
        .ErrorString = ""
        .MergeLabels = False
        .NullString = ""
        .PageFieldOrder = 2
        .PageFieldWrapCount = 0
        .PreserveFormatting = True
        .RowGrand = True
        .SaveData = True
        .PrintTitles = False
        .RepeatItemsOnEachPrintedPage = True
        .TotalsAnnotation = False
        .CompactRowIndent = 1
        .InGridDropZones = False
        .DisplayFieldCaptions = True
        .DisplayMemberPropertyTooltips = False
        .DisplayContextTooltips = True
        .ShowDrillIndicators = True
        .PrintDrillIndicators = False
        .AllowMultipleFilters = False
        .SortUsingCustomLists = True
        .FieldListSortAscending = False
        .ShowValuesRow = False
        .CalculatedMembersInFilters = False
        .RowAxisLayout xlCompactRow
    End With
    With ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotCache
        .RefreshOnFileOpen = False
        .MissingItemsLimit = xlMissingItemsDefault
    End With
    ActiveSheet.PivotTables("Tableau croisé dynamique2").RepeatAllLabels _
        xlRepeatLabels
    With ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotFields("id_vdr")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotFields( _
        "partenaire")
        .Orientation = xlColumnField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotFields("contrat" _
        )
        .Orientation = xlColumnField
        .Position = 2
    End With
    ActiveSheet.PivotTables("Tableau croisé dynamique2").AddDataField ActiveSheet. _
        PivotTables("Tableau croisé dynamique2").PivotFields("com"), "Somme de com", _
        xlSum
End Sub
A vrai dire je bloque sur cette partie
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "ventes aout!R1C1:R94C5", Version:=8).CreatePivotTable TableDestination:= _
        "Feuil2!R3C1", TableName:="Tableau croisé dynamique2", DefaultVersion:=8
Le code doit être dynamique car la taille du tableau peut varier.

PS : Je ne veux pas juste du code tout fait quelques pistes et explications me conviendront parfaitement