Option Explicit
Sub Interpolation()
'
' Interpolation Macro
' Interpolation linéaire entre deux taux libor pour une date valeur donnée et sa durée de vie en jour.
'
'
Dim nbjexact As Integer
Dim nbjinf As Integer
Dim nbjsup As Integer
Dim txlibinf As Double
Dim txlibsup As Double
Dim DateValeur As Date
Dim txinterpol As Double
Dim i As Integer
For i = 2 To Range("AR" & Range("AR65536").End(xlUp).Row)
nbjexact = Workbooks("Interpolation.xlsm").Sheets("PTF APPOLO").Range("AQ" & i)
DateValeur = Workbooks("Interpolation.xlsm").Sheets("PTF APPOLO").Range("I" & i)
If 1 <= nbjexact And nbjexact <= 7 Then
nbjinf = 1
nbjsup = 7
txlibinf = WorksheetFunction.Lookup(Workbooks("Interpolation. xlsm").Sheets("PTF APPOLO").Range("I" & i), Workbooks("Interpolation.xlsxm.xlsm").Sheets("Hist orique Libor aout").Range("A1:A100"), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("B1:B100"))
txlibsup = WorksheetFunction.Lookup(Workbooks("Interpolation. xlsm").Sheets("PTF APPOLO").Range("I" & i), Workbooks("Interpolation.xlsxm.xlsm").Sheets("Hist orique Libor aout").Range("D1100"), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("E1:E100"))
ElseIf 7 <= nbjexact And nbjexact <= 30 Then
nbjinf = 7
nbjsup = 30
txlibinf = WorksheetFunction.Lookup(Workbooks("Interpolation. xlsm").Sheets("PTF APPOLO").Range("I" & i), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("D1100"), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("E1:E100"))
txlibsup = WorksheetFunction.Lookup(Workbooks("Interpolation. xlsm").Sheets("PTF APPOLO").Range("I" & i), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("G1:G100"), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("H1:H100"))
ElseIf 30 <= nbjexact And nbjexact <= 60 Then
nbjinf = 30
nbjsup = 60
txlibinf = WorksheetFunction.Lookup(Workbooks("Interpolation. xlsm").Sheets("PTF APPOLO").Range("I" & i), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("G1:G100"), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("H1:H100"))
txlibsup = WorksheetFunction.Lookup(Workbooks("Interpolation. xlsm").Sheets("PTF APPOLO").Range("I" & i), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("J1:J100"), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("K1:K100"))
ElseIf 60 <= nbjexact And nbjexact <= 90 Then
nbjinf = 60
nbjsup = 90
txlibinf = WorksheetFunction.Lookup(Workbooks("Interpolation. xlsm").Sheets("PTF APPOLO").Range("I" & i), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("$J$1:$J$100"), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("$K$1:$K$100"))
txlibsup = WorksheetFunction.Lookup(Workbooks("Interpolation. xlsm").Sheets("PTF APPOLO").Range("I" & i), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("$M$1:$M$100"), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("$N$1:$N$100"))
Else
nbjinf = 90
nbjsup = 120
txlibinf = WorksheetFunction.Lookup(Workbooks("Interpolation. xlsxm.xlsm").Sheets("PTF APPOLO").Range("I" & i), Workbooks("Interpolation.xlsxm.xlsm").Sheets("Hist orique Libor aout").Range("M1:M100"), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("N1:N100"))
txlibsup = WorksheetFunction.Lookup(Workbooks("Interpolation. xlsxm.xlsm").Sheets("PTF APPOLO").Range("I" & i), Workbooks("Interpolation.xlsxm.xlsm").Sheets("Hist orique Libor aout").Range("P1:P100"), Workbooks("Interpolation.xlsm").Sheets("Historique Libor aout").Range("Q1:Q100"))
End If
txinterpol = (((txlibsup - txlibinf) * (nbjexact - nbjinf)) / (nbjsup - nbjinf)) + txlibinf
Range("AR" & i) = txinterpol
Next
End Sub