Excel Interpolation Linéaire VBA

cette fonction à interpoler/extrapole une table de x,y
Par exemple,

x y
1 10
2 15
3 20

Linterp(A1:B3, -1) = 0

Toutefois, ce code ne peut le faire à deux adjacents tableaux.
Je voudrais modifier ce code afin que je puisse
sélectionnez deux tableaux distincts, par exemple N106:N109,P106:P109.
Comment puis-je faire ce réglage dans ce code?

Function Linterp(r As Range, x As Double) As Double
     ' linear interpolator /extrapolator
     ' R is a two-column range containing known x, known y
    Dim lR As Long, l1 As Long, l2 As Long
    Dim nR As Long
     'If x = 1.5 Then Stop

    nR = r.Rows.Count
    If nR < 2 Then Exit Function

    If x < r(1, 1) Then ' x < xmin, extrapolate
        l1 = 1: l2 = 2: GoTo Interp

    ElseIf x > r(nR, 1) Then ' x > xmax, extrapolate
        l1 = nR - 1: l2 = nR: GoTo Interp

    Else
         ' a binary search would be better here
        For lR = 1 To nR
            If r(lR, 1) = x Then ' x is exact from table
                Linterp = r(lR, 2)
                Exit Function

            ElseIf r(lR, 1) > x Then ' x is between tabulated values, interpolate
                l1 = lR: l2 = lR - 1: GoTo Interp

            End If
        Next
    End If

Interp:
    Linterp = r(l1, 2) _
    + (r(l2, 2) - r(l1, 2)) _
    * (x - r(l1, 1)) _
    / (r(l2, 1) - r(l1, 1))

End Function
  • Si une plage discontinue est passée, vous pouvez détecter que l'utilisation de r.Areas.Count
  • Désolé mais je suis nouveau sur VBA. qu'est-r.Les zones.Le comte exactement?