Excel Linear Interpolation VBA - Stack Overflow
stackoverflow.com › questions › 36455864Oct 02, 2015 · 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 ...