Ajouter une condition à une macro

INFINITY100

XLDnaute Occasionnel
Bonjour à tous

Voila je suis face à un problème d'ajout d'une condition à ma macro ci-dessous, en effet je voudrai ajouter cette condition : si le mot qui se trouve en colonne D est "Dette" alors la couleur du texte est rouge sinon si le mot est "Règlement" alors la couleur du texte est bleu

Voici ma macro

Code:
Derlig = Sheets("BD_Dettes_Règlements").[B10014].End(xlUp).Row
  For Lig = 14 To Derlig
  With Cells(Lig, "B").Resize(, 6)
      .Borders.LineStyle = xlContinuous
      .HorizontalAlignment = xlCenter
      .Interior.ColorIndex = 19
      .Font.ColorIndex = 3
      .RowHeight = 18
      .Font.Size = 12
    End With

Merci par avance à vous tous

Cordialement
 

Hieu

XLDnaute Impliqué
Salut,

Comme ça ?
VB:
Derlig = Sheets("BD_Dettes_Règlements").[B10014].End(xlUp).Row
  For Lig = 14 To Derlig
  With Cells(Lig, "B").Resize(, 6)
      .Borders.LineStyle = xlContinuous
      .HorizontalAlignment = xlCenter
      .Interior.ColorIndex = 19
      .Font.ColorIndex = 3
      .RowHeight = 18
      .Font.Size = 12
select case range("d" & Derlig)
       case "Dette": .Font.Color = -16776961 ' rouge
       case "Règlement" :  .Font.Color = -4165632 'bleu
end select
End With
Next Lig
 

Hieu

XLDnaute Impliqué
Re,

Petite correction:
VB:
Sub couleur()
Derlig = Sheets("BD_Dettes_Règlements").[B10014].End(xlUp).Row
  For Lig = 14 To Derlig
  With Cells(Lig, "B").Resize(, 6)
      .Borders.LineStyle = xlContinuous
      .HorizontalAlignment = xlCenter
      .Interior.ColorIndex = 19
      ' .Font.ColorIndex = 3
      .RowHeight = 18
      .Font.Size = 12
Select Case Range("d" & Lig)
    Case "Dette": .Font.Color = -16776961 ' rouge
    Case "Règlement": .Font.Color = -4165632 ' bleu
End Select
End With
Next Lig
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 084
Messages
2 085 192
Membres
102 809
dernier inscrit
Sandrine83