Bonjour,

J'ai codé ceci qui me permet de n'avoir dans mon TCD seulement les données de l'année en cours :

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
Sub ThisYear_Filter()
 
    'Variable declaration
    Dim strDate As String
    Dim strYear As String
 
    strDate = Format(Now, "yyyy") 'Takes the format of the date today and just takes the number of the year
 
    With Sheets("Safety & Airworthiness actions").PivotTables("S_PivotTable").PivotFields("Year") 'Active filter just on this array and this filter
            For Each X In Sheets("Safety & Airworthiness actions").PivotTables("S_PivotTable").PivotFields("Year").PivotItems 'Read each field of the filter and go through them
            strYear = X 'Stock the year in a String variable
                    If .PivotItems(strYear) <> .PivotItems(strDate) Then 'If the filter date is different from the current date
                    .PivotItems(strYear).Visible = False 'Puts the filter inactive
                    End If
            Next
    End With
End Sub
J'ai fait exactement la même chose pour n'avoir que les données du mois en cours, mais le IF semble bloquer ...

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
Sub ThisMonth_Filter()
 
    'Variable declaration
    Dim strDate As String
    Dim strMonth As String
 
    strDate = Format(Now, "mmmm") 'Takes the month of today
 
    With Sheets("Safety & Airworthiness actions").PivotTables("S_PivotTable").PivotFields("Month") 'Active filter just on this array and this filter
            For Each X In Sheets("Safety & Airworthiness actions").PivotTables("S_PivotTable").PivotFields("Month").PivotItems 'Read each field of the filter and go through them
            strMonth = X 'Stock the month in a String variable
            strMonth = Choose(X, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
                    If .PivotItems(strMonth) <> .PivotItems(strDate) Then 'if the filter date is different from the current date
                    .PivotItems(strMonth).Visible = False 'Puts the filter inactive
                    Sheets("Safety & Airworthiness actions").PivotTables("S_PivotTable").PivotFields("Year").ShowDetail = True
                    End If
            Next
    End With
End Sub
La ligne strMonth = Choose (X,...) est là parce que dans mon tableau de données pour mon TCD ils sont au format "mmmm".

Est-il possible de m'aider ?