Sub Test2()
With Range("A10:" & Range("A65536").End(xlUp).Address).Offset(0, 10)
.Formula = "=IF(OR(AND(R1C1<>""xxx"",R[3]C[-8]=""""),(R[3]C[-8]="""")),"""",IF(R1C1=""xxx"",MAX(([Test.xls]Feuil1!R2C3:R65536C3=R1C2)*(([Test.xls]Feuil1!R2C2:R65536C2+[Test.xls]Feuil1!R2C1:R65536C1)<=(R[1]C[-10]+(R[1]C[-6]+0.5/24)))*([Test.xls]Feuil1!R2C1:R65536C1+[Test.xls]Feuil1!R2C2:R65536C2)),MAX(([Test.xls]Feuil1!R2C3:R65536C3=R[1]C[-8])*(([Test.xls]Feuil1!R2C2:R65536C2+[Test.xls]Feuil1!R2C1:R65536C1)<=(R[1]C[-10]+(R[1]C[-6]+0.5/24)))*([Test.xls]Feuil1!R2C1:R65536C1+[Test.xls]Feuil1!R2C2:R65536C2))))"
.Value = .Value
End With
End Sub