Option Explicit
Private Sub Worksheet_Calculate()
Dim lig As Long
Dim cle As String
Dim dic, dil
Set dic = CreateObject("Scripting.Dictionary")
Set dil = CreateObject("Scripting.Dictionary")
With ActiveSheet
For lig = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
If Left(Cells(lig, "O").Value, 5) = "ACHAT" Then
cle = Left(Cells(lig, "O").Value, 5) & Cells(lig, "P").Value
If Cells(lig, "S").Value = "attente" Then
If Not dic.exists(cle) Then
dic.Add cle, lig
dil.Add lig, cle
End If
End If
ElseIf Cells(lig, "P").Value <> "" Then
Cells(lig, "P").Interior.ThemeColor = xlThemeColorDark1
Cells(lig, "P").Font.ThemeColor = xlThemeColorDark1
End If
Next lig
For lig = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
cle = Left(Cells(lig, "O").Value, 5) & Cells(lig, "P").Value
If dic.exists(cle) And Not dil.exists(lig) Then
Cells(lig, "O").Value = "ACHAT@"
Cells(lig, "O").Interior.ThemeColor = xlThemeColorDark1
Cells(lig, "O").Font.ThemeColor = xlThemeColorDark1
Cells(lig, "P").Interior.ThemeColor = xlThemeColorDark1
Cells(lig, "P").Font.ThemeColor = xlThemeColorDark1
End If
Next lig
End With
End Sub