Couleur bouton selon valeur cellule

Résolu
Bonjour,
j'ai un soucis avec un "CommandButton" je lui modifie le texte selon la valeur d'une Cellule D1
qui me donne "FACTURE" ou "DEVIS" selon la valeur de D1
Mais je voudrais lui changer la couleur Rouge ou vert et je bloque je vous mets la macro

Private Sub Worksheet_Change(ByVal Target As Range)
CommandButton1.Caption = Range("D1")
Range("D1") = "FACTURE" = CommandButton1.BackColor = RGB(255, 0, 0)
'Range("D1") = "DEVIS" = CommandButton1.BackColor = RGB(200, 0, 0)
End Sub
Merci de votre aide

Slts A bientôt
Surplus

2 réponses

  1. Bonjour,

    Comme cela

    Private Sub Worksheet_Change(ByVal Target As Range)
    CommandButton1.Caption = Range("D1")
    If Range("D1") = "FACTURE" Then CommandButton1.BackColor = RGB(255, 0, 0)
    If Range("D1") = "DEVIS" Then CommandButton1.BackColor = RGB(200, 0, 0)
    End Sub

    ou encore comme cela

    Private Sub Worksheet_Change(ByVal Target As Range)
    CommandButton1.Caption = Range("D1")
    If Range("D1") = "FACTURE" Then CommandButton1.BackColor = &HFF&
    If Range("D1") = "DEVIS" Then CommandButton1.BackColor = &HC8&
    End Sub

    A+
    Mike-31

    Une période d'échec est un moment rêvé pour semer les graines du savoir.
    0
    1. Bonjour
      Ca fonctionne très bien
      Merci de ton aide
      --
      Slts A bientôt
      Surplus
      0