I have the following functions in VBA:
Function weightedAverage(x0, y0, x1, y1, x)
weightedAverage = y0 + (x - x0) * (y1 - y0) / (x1 - x0)
End Function
Function interpolateLookup(lookupVal As Range, lookupRange As Range, colID As Integer) As Double
step = 0.01
x0 = Application.Round(lookupVal.Value, 3)
y0 = Application.VLookup(x0, lookupRange, colID, True)
x1 = Application.Round(lookupVal.Value, 3) + step
y1 = Application.VLookup(x1, lookupRange, colID, False)
x = lookupVal.Value
interpolateLookup = weightedAverage(x0, y0, x1, y1, x)
End Function
The problem here is that my interpolateLookup function returns a #VALUE! error when I pass it the following input:
=interpolateLookup(E5,K3:O803,5)
Why???
y0ory1are returning an error value.