Bonjour,

Je me permet de revenir encore une fois vers vous pour vous demander de l'aide. Et pourtant je suis aller voir sur de nombreux forum avant de faire ce post!

Voilà, je voudrais que ma macro actualise mes TCD en fonction des items retenu dans une plage de cellule. Cette plage de cellule est renseigné par mon formulaire "Paramètre. L'idée était qu'il m'actualise le TCD en fonction de ses items.

Seulement en fonction des option retenu soit il m'affiche qu'un seule items soit il m'affiche rien. !
D'avance Merci.

Liens vers mon fichier: http://cjoint.com/?3DlkadZyKqv

La première macro: (J'ai un problème au If! Je n'ai pas très bien compris la sélection dans un tableau)

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
Sub Macro3()
' Mise a Jour TCD
Dim wsd As Worksheet, _
    wss As Worksheet, _
    strPT As String, strPF As String, _
    pi As PivotItem
Dim item As String
 
    Application.ScreenUpdating = False
 
    Set wsd = Worksheets("04 - Synthèse Agence Echu")
    Set wss = Worksheets("01 - Menu")
    strPT = "Tableau croisé dynamique2"
    strPF = "Libellé Pdv"
 
    With wsd.PivotTables(strPT).PivotFields(strPF)
        .ClearAllFilters
        .AutoSort xlAscending, strPF
    End With
 
    With wss          
 
          For Each pi In wsd.PivotTables(strPT).PivotFields(strPF).PivotItems
            If .Range("tblAgences[Agences]").Find(what:=pi, _
                LookIn:=xlValues, lookat:=xlWhole).Row = pi.Name Then 'si il trouve ma valeur qui est égale au champ du TCD,
'il regarde dans la table et trouve la valeur qui doit être strictement égale. Si elle est égale elle sera visible!
             pi.Visible = True
        Else
                pi.Visible = False 'sinon elle est masqué!
           End If
        Next pi
 
        wsd.PivotTables(strPT).RefreshTable
 
    End With
 
    wsd.Activate
    [B1].Select
 
    Set wsd = Nothing: Set wss = Nothing
 
End Sub

La seconde macro: (La seconde me fait le filtre sur qu'une seule valeur.)

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
Sub Macro3()
' Mise a Jour TCD
Dim wsd As Worksheet, _
    wss As Worksheet, _
    strPT As String, strPF As String, _
    pi As PivotItem
Dim item As String
Dim i As Single
 
    Application.ScreenUpdating = False
 
    Set wsd = Worksheets("04 - Synthèse Agence Echu")
    Set wss = Worksheets("01 - Menu")
    strPT = "Tableau croisé dynamique2"
    strPF = "Libellé Pdv"
 
    With wsd.PivotTables(strPT).PivotFields(strPF)
        .ClearAllFilters
        .AutoSort xlAscending, strPF
    End With
 
    With wss
 
   For i = 4 To 10
    item = Cells(i + 1, 14)
      For Each pi In wsd.PivotTables(strPT).PivotFields(strPF).PivotItems
            On Error Resume Next
            If pi.Name = item Then
                pi.Visible = True
            Else
                pi.Visible = False
            End If
        Next pi
    Next i            
 
        wsd.PivotTables(strPT).RefreshTable
 
    End With
 
    wsd.Activate
    [B1].Select
 
    Set wsd = Nothing: Set wss = Nothing
 
End Sub