Bonjour,

Je suis en train de développer un programme sous VBA pour actualiser plusieurs TCD. Le temps d'exécution est trop long (avec ci peu de données je n'ose pas imaginer dans 1 an quand ma base sera plus concécante). Pourriez vous regarder mon code et m'aider dans l'optimisation de celui-ci?
Ci joint le code
En vous remerciant par avance.

Cordialement

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
Sub Modif_TCD_Rapport()
' Rafraichissment de tous les TCD
ActiveWorkbook.RefreshAll
' Modif_TCD_Rapport Macro
'
' Activation de la fenêtre "TCD rapport"
    Worksheets("Rapport").Activate
 
' Modification des champs de filtre TCD8
    ActiveSheet.PivotTables("TCD8").PivotFields("ANNEE").ClearAllFilters
    ActiveSheet.PivotTables("TCD8").PivotFields("ANNEE").CurrentPage = Rapport.ComboBox2.Value
    ActiveSheet.PivotTables("TCD8").PivotFields("MOIS").ClearAllFilters
    ActiveSheet.PivotTables("TCD8").PivotFields("MOIS").CurrentPage = Rapport.ComboBox3.Value
 
' Modification des champs de filtre TCD6
    ActiveSheet.PivotTables("TCD6").PivotFields("ANNEE").ClearAllFilters
    ActiveSheet.PivotTables("TCD6").PivotFields("ANNEE").CurrentPage = Rapport.ComboBox2.Value
    ActiveSheet.PivotTables("TCD6").PivotFields("MOIS").ClearAllFilters
    ActiveSheet.PivotTables("TCD6").PivotFields("MOIS").CurrentPage = Rapport.ComboBox3.Value
 
' Modification des champs de filtre TCD7
    ActiveSheet.PivotTables("TCD7").PivotFields("ANNEE").ClearAllFilters
    ActiveSheet.PivotTables("TCD7").PivotFields("ANNEE").CurrentPage = Rapport.ComboBox2.Value
    ActiveSheet.PivotTables("TCD7").PivotFields("MOIS").ClearAllFilters
    ActiveSheet.PivotTables("TCD7").PivotFields("MOIS").CurrentPage = Rapport.ComboBox3.Value
 
 With ActiveSheet.PivotTables("TCD6").PivotFields("SECTION")
        .PivotItems("").Visible = True
        .PivotItems("M00").Visible = False
        .PivotItems("M01").Visible = False
        .PivotItems("M02").Visible = False
        .PivotItems("M10").Visible = False
        .PivotItems("M20").Visible = False
        .PivotItems("M22").Visible = False
        .PivotItems("M24").Visible = False
        .PivotItems("M25").Visible = False
        .PivotItems("M26").Visible = False
        .PivotItems("M27").Visible = False
        .PivotItems("M31").Visible = False
        .PivotItems("M34").Visible = False
        .PivotItems("M41").Visible = False
        .PivotItems("M44").Visible = False
        .PivotItems("M45").Visible = False
        .PivotItems("M46").Visible = False
        .PivotItems("M47").Visible = False
        .PivotItems("M50").Visible = False
        .PivotItems("M60").Visible = False
        .PivotItems("M62").Visible = False
        .PivotItems("M70").Visible = False
        .PivotItems("M81").Visible = False
    End With
 
    With ActiveSheet.PivotTables("TCD7").PivotFields("SECTION")
        .PivotItems("").Visible = True
        .PivotItems("M00").Visible = False
        .PivotItems("M01").Visible = False
        .PivotItems("M02").Visible = False
        .PivotItems("M10").Visible = False
        .PivotItems("M20").Visible = False
        .PivotItems("M22").Visible = False
        .PivotItems("M24").Visible = False
        .PivotItems("M25").Visible = False
        .PivotItems("M26").Visible = False
        .PivotItems("M27").Visible = False
        .PivotItems("M31").Visible = False
        .PivotItems("M34").Visible = False
        .PivotItems("M41").Visible = False
        .PivotItems("M44").Visible = False
        .PivotItems("M45").Visible = False
        .PivotItems("M46").Visible = False
        .PivotItems("M47").Visible = False
        .PivotItems("M50").Visible = False
        .PivotItems("M60").Visible = False
        .PivotItems("M62").Visible = False
        .PivotItems("M70").Visible = False
        .PivotItems("M81").Visible = False
    End With
 
 
' Si la sélection est = à M00 ou M02 alors Champ de filtre TCD6 et TCD7 = M00 et M02
    If Rapport.ComboBox1.ListIndex = 0 Or Rapport.ComboBox1.ListIndex = 2 Then
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M00").Visible = True
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M02").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M00").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M02").Visible = True
    End If
 
' Si la sélection est = à M01 ou M10 ou M81 alors Champ de filtre TCD6 et TCD7 = M01 et M10 et M81
    If Rapport.ComboBox1.ListIndex = 1 Or Rapport.ComboBox1.ListIndex = 3 Or Rapport.ComboBox1.ListIndex = 24 Then
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M01").Visible = True
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M10").Visible = True
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M81").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M01").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M10").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M81").Visible = True
    End If
 
' Si la sélection est = à M20 ou M27 alors Champ de filtre TCD6 et TCD7 = M20 et M27
    If Rapport.ComboBox1.ListIndex = 4 Or Rapport.ComboBox1.ListIndex = 9 Then
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M20").Visible = True
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M27").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M20").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M27").Visible = True
    End If
 
' Si la sélection est = à M22 alors Champ de filtre TCD6 et TCD7 = M22
    If Rapport.ComboBox1.ListIndex = 5 Then
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M22").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M22").Visible = True
    End If
 
' Si la sélection est = à M24 ou M25 alors Champ de filtre TCD6 et TCD7 = M24 et M25
    If Rapport.ComboBox1.ListIndex = 6 Or Rapport.ComboBox2.ListIndex = 7 Then
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M24").Visible = True
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M25").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M24").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M25").Visible = True
    End If
 
' Si la sélection est = à M26 ou M31 ou M34 alors Champ de filtre TCD6 et TCD7 = M26 et M31 et M34
    If Rapport.ComboBox1.ListIndex = 8 Or Rapport.ComboBox1.ListIndex = 10 Or Rapport.ComboBox1.ListIndex = 11 Then
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M26").Visible = True
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M31").Visible = True
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M34").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M26").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M31").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M34").Visible = True
    End If
 
' Si la sélection est = à M41 ou M43 alors Champ de filtre TCD6 et TCD7 = M41 et M43
    If Rapport.ComboBox1.ListIndex = 12 Or Rapport.ComboBox1.ListIndex = 13 Then
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M41").Visible = True
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M43").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M41").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M43").Visible = True
    End If
 
' Si la sélection est = à M44 alors Champ de filtre TCD6 et TCD7 = M44
    If Rapport.ComboBox1.ListIndex = 14 Then
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M44").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M44").Visible = True
    End If
 
' Si la sélection est = à M45 ou M46 alors Champ de filtre TCD6 et TCD7 = M45 et M46
    If Rapport.ComboBox1.ListIndex = 15 Or Rapport.ComboBox1.ListIndex = 16 Then
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M45").Visible = True
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M46").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M45").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M46").Visible = True
    End If
 
' Si la sélection est = à M47 alors Champ de filtre TCD6 et TCD7 = M47
    If Rapport.ComboBox1.ListIndex = 17 Then
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M47").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M47").Visible = True
    End If
 
' Si la sélection est = à M50 ou M51 alors Champ de filtre TCD6 et TCD7 = M50 et M51
    If Rapport.ComboBox1.ListIndex = 18 Or Rapport.ComboBox1.ListIndex = 19 Then
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M50").Visible = True
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M51").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M50").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M51").Visible = True
    End If
 
' Si la sélection est = à M60 alors Champ de filtre TCD6 et TCD7 = M60
    If Rapport.ComboBox1.ListIndex = 20 Then
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M60").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M60").Visible = True
    End If
 
' Si la sélection est = à M62 alors Champ de filtre TCD6 et TCD7 = M62
    If Rapport.ComboBox1.ListIndex = 21 Then
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M62").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M62").Visible = True
    End If
 
' Si la sélection est = à M70 alors Champ de filtre TCD6 et TCD7 = M70
    If Rapport.ComboBox1.ListIndex = 22 Then
        ActiveSheet.PivotTables("TCD6").PivotFields("SECTION").PivotItems("M70").Visible = True
        ActiveSheet.PivotTables("TCD7").PivotFields("SECTION").PivotItems("M70").Visible = True
    End If
 
 
' définition de la police et du fond des celulles E29 à I150
    Range("E29:I150").Select
    With Selection.Font
        .Name = "Calibri"
        .Size = 8
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ThemeColor = xlThemeColorLight1
        .TintAndShade = 0
        .ThemeFont = xlThemeFontMinor
    End With
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent2
        .TintAndShade = 0.799981688894314
        .PatternTintAndShade = 0
    End With
' définition de la police et du fond des celulles J29 à L150
    Range("J29:L150").Select
    With Selection.Font
        .Name = "Calibri"
        .Size = 8
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ThemeColor = xlThemeColorLight1
        .TintAndShade = 0
        .ThemeFont = xlThemeFontMinor
    End With
    With Selection.Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent3
        .TintAndShade = 0.799981688894314
        .PatternTintAndShade = 0
    End With
 
    ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").ClearAllFilters
 
    With ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2")
        .PivotItems("").Visible = True
        .PivotItems("M20").Visible = False
        .PivotItems("M22").Visible = False
        .PivotItems("M27").Visible = False
        .PivotItems("M44").Visible = False
        .PivotItems("M45").Visible = False
        .PivotItems("M70").Visible = False
    End With
 
' Si la sélection est = à M00 ou M02 alors Champ de filtre TCD9 = M00 et M02
    If Rapport.ComboBox1.ListIndex = 0 Or Rapport.ComboBox1.ListIndex = 2 Then
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M00").Visible = True
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M02").Visible = True
    End If
 
' Si la sélection est = à M01 ou M10 ou M81 alors Champ de filtre TCD9 = M01 et M10 et M81
    If Rapport.ComboBox1.ListIndex = 1 Or Rapport.ComboBox1.ListIndex = 3 Or Rapport.ComboBox1.ListIndex = 24 Then
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M01").Visible = True
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M10").Visible = True
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M81").Visible = True
    End If
 
' Si la sélection est = à M20 ou M27 alors Champ de filtre TCD9 = M20 et M27
    If Rapport.ComboBox1.ListIndex = 4 Or Rapport.ComboBox1.ListIndex = 9 Then
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M20").Visible = True
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M27").Visible = True
    End If
 
' Si la sélection est = à M22 alors Champ de filtre TCD9 = M22
    If Rapport.ComboBox1.ListIndex = 5 Then
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M22").Visible = True
    End If
 
' Si la sélection est = à M24 ou M25 alors Champ de filtre TCD9 = M24 et M25
    If Rapport.ComboBox2.ListIndex = 6 Or Rapport.ComboBox2.ListIndex = 7 Then
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M24").Visible = True
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M25").Visible = True
    End If
 
' Si la sélection est = à M26 ou M31 ou M34 alors Champ de filtre TCD9 = M26 et M31 et M34
    If Rapport.ComboBox1.ListIndex = 8 Or Rapport.ComboBox1.ListIndex = 10 Or Rapport.ComboBox1.ListIndex = 11 Then
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M26").Visible = True
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M31").Visible = True
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M34").Visible = True
    End If
 
' Si la sélection est = à M41 ou M43 alors Champ de filtre TCD9 = M41 et M43
    If Rapport.ComboBox1.ListIndex = 12 Or Rapport.ComboBox1.ListIndex = 13 Then
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M41").Visible = True
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M43").Visible = True
    End If
 
' Si la sélection est = à M44 alors Champ de filtre TCD9 = M44
    If Rapport.ComboBox1.ListIndex = 14 Then
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M44").Visible = True
    End If
 
' Si la sélection est = à M45 ou M46 alors Champ de filtre TCD9 = M45 et M46
    If Rapport.ComboBox1.ListIndex = 15 Or Rapport.ComboBox1.ListIndex = 16 Then
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M45").Visible = True
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M46").Visible = True
    End If
 
' Si la sélection est = à M47 alors Champ de filtre TCD9 = M47
    If Rapport.ComboBox1.ListIndex = 17 Then
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M47").Visible = True
    End If
 
' Si la sélection est = à M50 ou M51 alors Champ de filtre TCD9 = M50 et M51
    If Rapport.ComboBox1.ListIndex = 18 Or Rapport.ComboBox1.ListIndex = 19 Then
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M50").Visible = True
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M51").Visible = True
    End If
 
' Si la sélection est = à M60 alors Champ de filtre TCD9 = M60
    If Rapport.ComboBox1.ListIndex = 20 Then
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M60").Visible = True
    End If
 
' Si la sélection est = à M62 alors Champ de filtre TCD9 = M62
    If Rapport.ComboBox1.ListIndex = 21 Then
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M62").Visible = True
    End If
 
' Si la sélection est = à M70 alors Champ de filtre TCD9 = M70
    If Rapport.ComboBox1.ListIndex = 22 Then
        ActiveSheet.PivotTables("TCD9").PivotFields("SECTION2").PivotItems("M70").Visible = True
    End If
 
End Sub