Bonjour à tous,

J'ai mon programme qui produit une erreur 9 lorsque i prend la valeur 7.
Je démarre ma boucle à 4 et l'erreur apparait avec Code(i, 1) = ...

Quelqu'un peut-il m'expliquer l'erreur ?

Je vous joins le fichier au cas où.
test.xlsm

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
 
Sub Valeur_vers_codification_indice()
 
Dim Cloture, Code, i As Long, pourcentage As Double, Dcel As Range, x As Long
 
ActiveWorkbook.Worksheets("Valeur").Activate
Set Dcel = Range("B" & Rows.Count).End(xlUp)(1, 2)
Cloture = Range("B5", Dcel)
Set Dce2 = Range("C" & Rows.Count).End(xlUp)(1, 2)
Code = Range("C5", Dce2)
 
For i = 4 To UBound(Cloture)
        If Cloture(i, 1) = Cloture(i - 2, 1) And Cloture(i - 1, 1) > Cloture(i, 1) And Cloture(i - 3, 1) < Cloture(i, 1) Then
            Code(i, 1) = "r-"
        ElseIf Cloture(i, 1) = Cloture(i - 2, 1) And Cloture(i - 1, 1) > Cloture(i, 1) And Cloture(i - 3, 1) > Cloture(i, 1) Then
            If Cloture(i + 1, 1) > Cloture(i, 1) Then
            Code(i, 1) = "E+"
            Else
            Code(i, 1) = "e"
            End If
        ElseIf Cloture(i, 1) = Cloture(i - 2, 1) And Cloture(i - 1, 1) > Cloture(i, 1) And Cloture(i - 3, 1) > Cloture(i, 1) Then
            Code(i, 1) = "r-"
        ElseIf Cloture(i, 1) = Cloture(i - 2, 1) And Cloture(i - 1, 1) > Cloture(i, 1) And Cloture(i - 3, 1) < Cloture(i, 1) Then
            If Cloture(i + 1, 1) < Cloture(i, 1) Then
            Code(i, 1) = "E-"
            Else
            Code(i, 1) = "r"
            End If
 
        ElseIf Cloture(i - 2, 1) > Cloture(i - 1, 1) Then
            If Cloture(i, 1) < Cloture(i - 1, 1) Then
                Code(i, 1) = "e1"
            ElseIf Cloture(i, 1) > Cloture(i - 1, 1) Then
                If Cloture(i, 1) > Cloture(i - 2, 1) Then
                    Code(i, 1) = "r+"
                Else
                    Code(i, 1) = "e+"
                End If
            End If
        ElseIf Cloture(i - 2, 1) < Cloture(i - 1, 1) Then
            If Cloture(i, 1) > Cloture(i - 1, 1) Then
                Code(i, 1) = "r1"
            ElseIf Cloture(i, 1) < Cloture(i - 1, 1) Then
                If Cloture(i, 1) < Cloture(i - 2, 1) Then
                    Code(i, 1) = "e-"
                Else
                    Code(i, 1) = "r-"
                End If
            End If
        End If
Next i
Range("C" & Rows.Count).End(xlUp)(1, 2) = Code
Range("C5").Resize(UBound(Cloture, 1), UBound(Cloture, 2)) = Code
End Sub