Function Ecart$(xplage As Range, xmini As Range, xmaxi As Range)
Dim min#, max#, t, x, ecartmin#, ecartneg#, ecartpos#, nbv&
t = xplage.Value2: min = xmini.Value2: max = xmaxi.Value2
For Each x In t
If x = "" Then
nbv = nbv + 1
ElseIf x < min Then
ecartneg = ecartneg + (min - x)
ElseIf x > max Then
ecartpos = ecartpos + (x - max)
End If
Next x
If nbv = xplage.Cells.Count Then
Ecart = "": Exit Function
ElseIf Abs(ecartneg - ecartpos) < 0.000001 Then
Ecart = Format(0, "hh:mm:ss")
ElseIf ecartneg > ecartpos Then
Ecart = "- " & Format(ecartneg - ecartpos, "hh:mm:ss")
Else
Ecart = "+ " & Format(ecartpos - ecartneg, "hh:mm:ss")
End If
End Function