bonjour

j'essaye de créer un tableau croisé dynamique via vba en intégrant un filtre sur le rapport mais cela ne fonctionne pas.
quelqu'un d'entre vous peut-il m'aider merci.
Ci-dessous mon code (pb sur la partie en rouge gras)
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
Sub t_tcd2()
Sheets("fbl5n").Range("A1").Select
    Selection.CurrentRegion.Select
    'Création de la feuille de destination
    Set Feuille2 = Sheets("tcd2")
    
    On Error Resume Next
    Err2 = 0
    
    If Err2 <> 0 Then
        Application.DisplayAlerts = False
        ActiveSheet.Delete        'détruit la feuille créée
        Application.DisplayAlerts = True
    End If

    'Création du cache
    Set Cache2 = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="fbl5n!R1C1:R10000C15", Version:=xlPivotTableVersion12)

    'Création du tableau croisé dynamique
    Set TCD2 = Cache.CreatePivotTable(TableDestination:=Sheets("tcd2").Range("A3"), TableName:="fbl5n2", DefaultVersion:=xlPivotTableVersion12)


    'Définition et positionnement des champs dans le tableau
    
    
    With TCD2
           
            With .PivotFields("CNUM")
                 .Orientation = xlRowField
                 .Position = 1
            End With
            With .PivotFields("D/C")
                 .Orientation = xlColumnField
                 .Position = 1
            End With
            .AddDataField .PivotFields("Mtant en DI"), "montant", xlSum
              
    End With
    
    ActiveSheet.PivotTables("fbl5n2").PivotFields("Type"). _
    ClearAllFilters
    ActiveSheet.PivotTables("fbl5n2").PivotFields("Type"). _
    CurrentPage = "DR" 
   
ActiveSheet.Range("A4").Select
ligneTCD2 = Range("A4").End(xlDown).Row
End Sub