Code VBA colorier une cellule en vert grace à un userform

Bonjour,

J'ai créé un code concernant mon userform pour que lorsque je coche mon N° de chariot, la cellule qui y fait référence passe en "OK".

Le code n'est surement pas optimisé car je suis débutant en VBA mais il fonctionne très bien

La chose que je n'arrive pas à faire c'est transformer ce même code pour que la cellule passe en vert lorsque je coche l'un de mes chariots.

En résumé, dans mon code je souhaite remplacer le "OK" par "colorier la cellule en vert".

voici le code et en dessous à quoi ressemble mon userform :

Private Sub Valider_Click()
'Lorsque l'on coche le ou les chariots que l'on souhaite, saisie de "OK" dans la feuille "tableau de bord"
    Sheets("Tableau de bord").Select
'Chariot 1
    If Range("E9") = "OK" Or Range("E9") = "OK " Then GoTo Chariot_2
    If Chariot1.Value = True Then 'Si coché
        Range("E9") = "OK"
    Else 'Si décoché
        Range("E9") = "-"
    End If
Chariot_2:
    If Range("E10") = "OK" Or Range("E10") = "OK " Then GoTo Chariot_3
    If Chariot2.Value = True Then 'Si coché
        Range("E10") = "OK"
    Else 'Si décoché
        Range("E10") = "-"
    End If
Chariot_3:
    If Range("E11") = "OK" Or Range("E11") = "OK " Then GoTo Chariot_4
    If Chariot3.Value = True Then 'Si coché
        Range("E11") = "OK"
    Else 'Si décoché
        Range("E11") = "-"
    End If

Chariot_4:
    If Range("E12") = "OK" Or Range("E12") = "OK " Then GoTo Chariot_5
    If Chariot4.Value = True Then 'Si coché
        Range("E12") = "OK"
    Else 'Si décoché
        Range("E12") = "-"
    End If
Chariot_5:
    If Range("E13") = "OK" Or Range("E13") = "OK " Then GoTo Chariot_6
    If Chariot5.Value = True Then 'Si coché
        Range("E13") = "OK"
    Else 'Si décoché
        Range("E13") = "-"
    End If
Chariot_6:
    If Range("E14") = "OK" Or Range("E14") = "OK " Then GoTo Chariot_7
    If Chariot6.Value = True Then 'Si coché
        Range("E14") = "OK"
    Else 'Si décoché
        Range("E14") = "-"
    End If
Chariot_7:
    If Range("E15") = "OK" Or Range("E15") = "OK " Then GoTo Chariot_8
    If Chariot7.Value = True Then 'Si coché
        Range("E15") = "OK"
    Else 'Si décoché
        Range("E15") = "-"
    End If
Chariot_8:
    If Range("E16") = "OK" Or Range("E16") = "OK " Then GoTo Chariot_9
    If Chariot8.Value = True Then 'Si coché
        Range("E16") = "OK"
    Else 'Si décoché
        Range("E16") = "-"
    End If
Chariot_9:
    If Range("E17") = "OK" Or Range("E17") = "OK " Then GoTo Chariot_10
    If Chariot9.Value = True Then 'Si coché
        Range("E17") = "OK"
    Else 'Si décoché
        Range("E17") = "-"
    End If
Chariot_10:
    If Range("E18") = "OK" Or Range("E18") = "OK " Then GoTo Chariot_11
    If Chariot10.Value = True Then 'Si coché
        Range("E18") = "OK"
    Else 'Si décoché
        Range("E18") = "-"
    End If

Chariot_11:
    If Range("E19") = "OK" Or Range("E19") = "OK " Then GoTo Chariot_12
    If Chariot11.Value = True Then 'Si coché
        Range("E19") = "OK"
    Else 'Si décoché
        Range("E19") = "-"
    End If
Chariot_12:
    If Range("E20") = "OK" Or Range("E20") = "OK " Then GoTo Chariot_13
    If Chariot12.Value = True Then 'Si coché
        Range("E20") = "OK"
    Else 'Si décoché
        Range("E20") = "-"
    End If
Chariot_13:
    If Range("E21") = "OK" Or Range("E21") = "OK " Then GoTo Chariot_14
    If Chariot13.Value = True Then 'Si coché
        Range("E21") = "OK"
    Else 'Si décoché
        Range("E21") = "-"
    End If

Chariot_14:
    If Range("E22") = "OK" Or Range("E22") = "OK " Then GoTo Chariot_15
    If Chariot14.Value = True Then 'Si coché
        Range("E22") = "OK"
    Else 'Si décoché
        Range("E22") = "-"
    End If
Chariot_15:
    If Range("E23") = "OK" Or Range("E23") = "OK " Then GoTo Chariot_16
    If Chariot15.Value = True Then 'Si coché
        Range("E23") = "OK"
    Else 'Si décoché
        Range("E23") = "-"
    End If
Chariot_16:
    If Range("E24") = "OK" Or Range("E24") = "OK " Then GoTo Chariot_17
    If Chariot16.Value = True Then 'Si coché
        Range("E24") = "OK"
    Else 'Si décoché
        Range("E24") = "-"
    End If
Chariot_17:
    If Range("E25") = "OK" Or Range("E25") = "OK " Then GoTo Chariot_18
    If Chariot17.Value = True Then 'Si coché
        Range("E25") = "OK"
    Else 'Si décoché
        Range("E25") = "-"
    End If
Chariot_18:
    If Range("E26") = "OK" Or Range("E26") = "OK " Then GoTo Chariot_19
    If Chariot18.Value = True Then 'Si coché
        Range("E26") = "OK"
    Else 'Si décoché
        Range("E26") = "-"
    End If
Chariot_19:
    If Range("E27") = "OK" Or Range("E27") = "OK " Then GoTo Chariot_20
    If Chariot19.Value = True Then 'Si coché
        Range("E27") = "OK"
    Else 'Si décoché
        Range("E27") = "-"
    End If
Chariot_20:
    If Range("E28") = "OK" Or Range("E28") = "OK " Then GoTo Chariot_21
    If Chariot20.Value = True Then 'Si coché
        Range("E28") = "OK"
    Else 'Si décoché
        Range("E28") = "-"
    End If

Chariot_21:
    If Range("E29") = "OK" Or Range("E29") = "OK " Then GoTo Chariot_22
    If Chariot21.Value = True Then 'Si coché
        Range("E29") = "OK"
    Else 'Si décoché
        Range("E29") = "-"
    End If
Chariot_22:
    If Range("E30") = "OK" Or Range("E30") = "OK " Then GoTo Chariot_23
    If Chariot22.Value = True Then 'Si coché
        Range("E30") = "OK"
    Else 'Si décoché
        Range("E30") = "-"
    End If
Chariot_23:
    If Range("E31") = "OK" Or Range("E31") = "OK " Then GoTo Chariot_24
    If Chariot23.Value = True Then 'Si coché
        Range("E31") = "OK"
    Else 'Si décoché
        Range("E31") = "-"
    End If

Chariot_24:
    If Range("E32") = "OK" Or Range("E32") = "OK " Then GoTo Chariot_25
    If Chariot24.Value = True Then 'Si coché
        Range("E32") = "OK"
    Else 'Si décoché
        Range("E32") = "-"
    End If
Chariot_25:
    If Range("E33") = "OK" Or Range("E33") = "OK " Then GoTo Chariot_26
    If Chariot25.Value = True Then 'Si coché
        Range("E33") = "OK"
    Else 'Si décoché
        Range("E33") = "-"
    End If
Chariot_26:
    If Range("E34") = "OK" Or Range("E34") = "OK " Then GoTo Chariot_27
    If Chariot26.Value = True Then 'Si coché
        Range("E34") = "OK"
    Else 'Si décoché
        Range("E34") = "-"
    End If
Chariot_27:
    If Range("E35") = "OK" Or Range("E35") = "OK " Then GoTo Chariot_28
    If Chariot27.Value = True Then 'Si coché
        Range("E35") = "OK"
    Else 'Si décoché
        Range("E35") = "-"
    End If
Chariot_28:
    If Range("E36") = "OK" Or Range("E36") = "OK " Then GoTo Chariot_29
    If Chariot28.Value = True Then 'Si coché
        Range("E36") = "OK"
    Else 'Si décoché
        Range("E36") = "-"
    End If
Chariot_29:
    If Range("E37") = "OK" Or Range("E37") = "OK " Then GoTo Chariot_30
    If Chariot29.Value = True Then 'Si coché
        Range("E37") = "OK"
    Else 'Si décoché
        Range("E37") = "-"
    End If
Chariot_30:
    If Range("E38") = "OK" Or Range("E38") = "OK " Then GoTo fin
    If Chariot30.Value = True Then 'Si coché
        Range("E38") = "OK"
    Else 'Si décoché
        Range("E38") = "-"
    End If

'Sheets("Tableau déclaration Chariot").Select
'    ActiveWindow.SelectedSheets.Visible = False

fin:

    'Fermeture
    Unload Me

End Sub
image

Merci d'avance pour le temps qui vous allez me consacrer

Loïs

Bonjour

if range("E9")=true then
  Range("E9").interior.color  = 5287936
else
  Range("E9").interior.Pattern = xlNone
endif

A+ François

Bonjour François,

Tout d'abord merci pour ta réponse !

j'ai un petit ic. J'aimerais qu'il me garde les cellules déjà colorié en vert lorsque j'en resaisie une. Pour l'instant il la remplace..

Et deuxième ic, connais-tu le code couleur qui correspond au gris ? car mon tableau est de fond gris.

Merci

Re,

Un fichier est TOUJOURS le bienvenu (il y a tellement de nuance de gris) et de + je pourrais tester.

A+ François

Bonjour,

Veuillez m'excusez pour la réponse tardive mais j'ai trouvé la solution.

Merci à vous !

Rechercher des sujets similaires à "code vba colorier vert userform"