Bonjour à tous, je n'arrive pas à faire fonctionner ce bout de code... Disons que tout fonctionne hormis le fait de mettre à 0 le caption sur le sheet "Rapport Semaine".... et cela m'affiche aucune erreur... (j'ai mis en SOULIGNE la partie du code non fonctionnel...)

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
Function MAJ_graphique()
Sheets("Rapport Semaine").Activate
ActiveSheet.Unprotect "protection"

'Mise à jour des graphiques :
For j = 0 To 20 '20 graphiques (Le "0" compris)

    Select Case j
    Case 0 
    d = "Cuis"
    e = "A"
    f = "C"

    Case 1 
    d = "ACV"
    e = "D"
    f = "F"

    Case 2 
    d = "Extrudeur"
    e = "G"
    f = "I"

    Case 3 
    d = "6_1"
    e = "J"
    f = "L"

    Case 4 
    d = "4_5"
    e = "M"
    f = "O"
 
    Case 5 
    d = "4_1"
    e = "P"
    f = "R"

    Case 6 
    d = "3_2"
    e = "S"
    f = "U"
 
    Case 7 
    d = "test_1"
    e = "V"
    f = "X"
   
    Case 8 
    d = "test_2"
    e = "Y"
    f = "AA"
    
    Case 9 
    d = "poussière"
    e = "AB"
    f = "AD"

    Case 10 
    d = "Cendrier_2"
    e = "AE"
    f = "AG"
     
    Case 11 
    d = "Toaster_1_2"
    e = "AH"
    f = "AI"
 
    Case 12 
    d = "_1_2_R&D"
    e = "AH"
    f = "AJ"
    
    Case 13 
    d = "_1_2_Broyage"
    e = "AH"
    f = "AK"

    Case 14 
    d = "_1_2"
    e = "AL"
    f = "AM"

    Case 15
    d = "R&D"
    e = "AL"
    f = "AN"
    
    Case 16
    d = "Broyage"
    e = "AL"
    f = "AO"
    
    Case 17 
    d = "Stockage"
    e = "AP"
    f = "AR"
    
    Case 18 
    d = "_1"
    e = "AS"
    f = "AU"
    
    Case 19 
    d = "_2"
    e = "AV"
    f = "AX"

    Case 20 
    d = "Cendrier_1"
    e = "AY"
    f = "BA"

    End Select
    g = e & "3" & ":" & f
    h = e & "3" & ":" & e
    i = f & "3" & ":" & f
    
    
    'Mise en forme des graphiques (juste la date en abcisse x) :
    ActiveSheet.ChartObjects(d).Activate
    ActiveSheet.ChartObjects(d).Activate
    ActiveChart.Axes(xlCategory).Select
    Selection.TickLabels.NumberFormat = "dd.mm.yy;@"
    Application.CommandBars("Format Object").Visible = False

    'Traitement de MAJ Graphique :
    ActiveSheet.ChartObjects(d).Activate
    
    Lastdate = Sheets("BDD").Range(e & Rows.Count).End(xlUp)     'Dernière date
    If Lastdate = "Dates & Heures" Then GoTo reboucler
    Lastline = Sheets("BDD").Range(e & Rows.Count).End(xlUp).Row 'Dernière ligne
       
    Deconcatdate = Left(Lastdate, 10) 'Deconcaténation de l'heure
    Deconcatdate2 = Left(Lastdate, 2) 'Deconcaténation (pour obtenir le jour)
    LD = Lastdate - 6 'Lastdate - 7 jours
    LL = Lastline - 6 'Lastline - 7 lignes
          
Dim res As String
res = CStr(LD)

Dim res2 As Double
res2 = DateValue(res)

Do
x = Application.VLookup(res2, Sheets("BDD").Range(g & Lastline), 1, 1) 'Valeur de LD
res2 = res2 + 1
Loop While IsError(x) = True

colonne = 1
ligne = Application.Match(x, Sheets("BDD").Range(h & Lastline), False)

Var = ligne + 2

'Conditions spécifiques à Station BB (gestion 4 colonnes)
If j = 11 Or j = 12 Or j = 13 Or j = 14 Or j = 15 Or j = 16 Then
Var = Var - 15

If Var < 0 Then
'Forçage valeur par défaut
Var = 3
End If

End If

    If Lastline < 10 Then '-----------------------------------------------------------------
    
    With Worksheets("BDD")
        ActiveChart.SetSourceData Source:=Union(.Range(h & Lastline), .Range(i & Lastline)), PlotBy:=xlColumns
         '.MinimumScale = Sheets("Densité").Range("F6").Value - 6
         '.MinimumScale = Sheets("Densité").Range("F6").Value
    End With
    
        'Calcul du total en Kg pour la période
        With Sheets("Rapport Semaine")
        Total = "Label" & (j + 1)
        Test = Application.WorksheetFunction.Sum(Range("BDD!" & i & Lastline))
        If Test <> "" Then
        .OLEObjects(Total).Object.Caption = Application.WorksheetFunction.Sum(Range("BDD!" & i & Lastline))
        Else
        .OLEObjects(Total).Object.Caption = "0" 
        End If
        
        End With
    
    Else '----------------------------------------------------------------------------------
    
    With Worksheets("BDD")
        ActiveChart.SetSourceData Source:=Union(.Range(e & Var & ":" & e & Lastline), .Range(f & Var & ":" & f & Lastline)), PlotBy:=xlColumns
         '.MinimumScale = Sheets("Densité").Range("F7").Value
         '.MinimumScale = Sheets("Densité").Range("F6").Value
    End With
    
        'Calcul du total en Kg pour la période
        With Sheets("Rapport Semaine")
        Total = "Label" & (j + 1)

        k = f & Var & ":" & f & Lastline
        test2 = Application.WorksheetFunction.Sum(Range("BDD!" & k))
        If test2 <> "" Then
        .OLEObjects(Total).Object.Caption = Application.WorksheetFunction.Sum(Range("BDD!" & k))
        Else
         .OLEObjects(Total).Object.Caption = "0" 
        End If

        End With
        
    End If '--------------------------------------------------------------------------------

reboucler:
Next

ActiveSheet.Protect "protection"
End Function