Sub Test2()
Dim Rng As Range
[D4:F10000].Interior.ColorIndex = xlColorIndexNone
Set Rng = ColLignesOùCondR1C1([D4:F4], "RC1+RC2<>RC4+RC5")
If Rng Is Nothing Then Exit Sub
Rng.Interior.ColorIndex = 3
MsgBox "Anomalie détectée dans la date ou l'heure de vos " & [F2] & "." & Chr(10) & Chr(10) & _
"Apportez les modifications nécessaires et recommencez le test.", vbCritical, "Test de cohérence"
End Sub
Function ColLignesOùCondR1C1(ByVal CelDéb As Range, ByVal CondR1C1 As String) As Range
Rem. ——— Cellules partant de CélDéb dans sa colonne dont les lignes vérifient une condition R1C1 CondR1C1.
On Error Resume Next
Set ColLignesOùCondR1C1 = Intersect(LignesOùCondR1C1(CelDéb, CondR1C1), CelDéb.EntireColumn)
End Function
Function LignesOùCondR1C1(ByVal LigneDéb As Range, ByVal CondR1C1 As String) As Range
Rem. ——— Lignes entières partant de LigneDéb qui vérifient une condition R1C1 CondR1C1.
Dim Lignes As Range, ColTrv As Range
With LigneDéb.Worksheet.UsedRange
Set Lignes = LigneDéb.EntireRow.Resize(.Rows.Count + .Row - LigneDéb.Row)
Set ColTrv = Intersect(.Columns(.Columns.Count + 1), Lignes): End With
Application.ScreenUpdating = False
ColTrv.FormulaR1C1 = "=1/(" & CondR1C1 & ")"
On Error Resume Next
Set LignesOùCondR1C1 = ColTrv.SpecialCells(xlCellTypeFormulas, 1).EntireRow
ColTrv.Delete xlShiftToLeft
End Function