Function PrixILn(ByVal Qté As Double, ByVal RngTarifs As Range, ByVal LR As Byte) As Currency
Dim TQté(), TRat(), C As Byte, Qté0 As Double, Qté1 As Double
TQté = RngTarifs.Rows(1).Value
On Error Resume Next
C = WorksheetFunction.Match(Qté, TQté, 0)
On Error GoTo E
TRat = RngTarifs.Rows(LR + 1).Value
If C = 0 Then
PrixILn = Int(TRat(1, 1) * Qté * 100 + 0.5) / 100
ElseIf C = UBound(TRat, 2) Then
PrixILn = Int(TRat(1, C) * Qté * 100 + 0.5) / 100
Else
Qté0 = TQté(1, C): Qté1 = TQté(1, C + 1)
PrixILn = Int(IntpoLin(Qté, Qté0, TRat(1, C) * Qté0, _
Qté1, TRat(1, C + 1) * Qté1) * 100 + 0.5) / 100
End If
Exit Function
E: MsgBox Err.Description: Resume
End Function
Function IntpoLin(ByVal X As Double, ByVal X1 As Double, ByVal Y1 As Double, _
ByVal X2 As Double, ByVal Y2 As Double) As Double
IntpoLin = Y1 + (Y2 - Y1) * (X - X1) / (X2 - X1)
End Function