Problème dans boucle if

Résolu
Bonjour,

J'ai un code avec conditions. Lors de la compilation, une erreur m'indique que j'ai un "else" sans "if" (le dernier).
Pourtant, mon code me semble juste.
Quelqu'un peut-il y jeter un oeil ?

Merci d'avance
Sub Bouton14_QuandClic()

Dim dercol3 As Byte
Dim derline3 As Byte
dercol3 = Range("B4").End(xlToRight).Column
derline3 = Range("B4").End(xlDown).Row

Dim k As Byte
For k = 6 To dercol3 - 1

If Cells(4, k).Value < 0 Then
Cells(4, k).Select
    With Selection.Interior
        .ColorIndex = 35
        .Pattern = xlSolid
    End With

        ElseIf Cells(4, k).Value > 0 Then
        If Cells(4, k).Value < 10 Then
        Cells(4, k).Select
            With Selection.Interior
                .ColorIndex = 6
                .Pattern = xlSolid
            End With

                ElseIf Cells(4, k).Value > 10 Then
                    If Cells(4, k).Value < 20 Then
                    Cells(4, k).Select
                        With Selection.Interior
                            .ColorIndex = 44
                            .Pattern = xlSolid
                        End With

                            ElseIf Cells(4, k).Value > 20 Then
                            If Cells(4, k).Value < 50 Then
                            Cells(4, k).Select
                                With Selection.Interior
                                    .ColorIndex = 45
                                    .Pattern = xlSolid

                                        ElseIf Cells(4, k).Value > 50 Then
                                        Cells(4, k).Select
                                            With Selection.Interior
                                                .ColorIndex = 46
                                                .Pattern = xlSolid
                                            End With

                            End If
                    End If
         End If
End If


4 réponses

  1. Salut Jahawai

    Je crois qu'il manque un "End with" pour l'avant dernier "with", avant le dernier "ElseIf". Du coup la machine s'embrouille (elle "croit" être encore dans le "with")

    ++
    0
    1. Effectivement ;-(
      Je suis honteux, je ne l'avais pas vu...
      Merci beaucoup

      ++
      0
      1. Je reçois beaucoup d'aide sur les forum alors pour une fois que j'arrive à en donner...
        bonne programmation
        miou
        0
        1. héhé, moi aussi j'en reçois beaucoup, surtout ces derniers jours,
          Je fais très très peu de prog et je me fais avoir avec des "détails" comme celui-là que je ne vois pas instinctivement.
          Merci encore et bonne journée
          0