That last formula should be:
Interpolation = -(X1 - XVal) / (X2 - X1) * (Y2 - Y1) + Y1 ..
Better to define all local variables - easier to catch bugs, faster execution if
variables used as counters are of explicit integer types rather than variants
holding integers.
..
Bug. VB[A] doesn't perform 'short-circuit' boolean valuations like C, C++ and
Java do. It obstinately evaluates all expressions in the conditional of an If
statement. So on the first iteration of the For loop when i equals 1, VBA most
definitely does evaluate XRange.Cells(i - 1), which throws a runtime error. You
need to use nested Ifs to do this in VB[A].
VBA is unnecessary for this. Worksheet functions could be used, e.g.,
=TREND(
OFFSET(YRange,MATCH(XVal,XRange,SIGN(INDEX(XRange,2)-N(XRange)))-1,0,2,1),
OFFSET(XRange,MATCH(XVal,XRange,SIGN(INDEX(XRange,2)-N(XRange)))-1,0,2,1),
XVal)
if XRange and YRange were both single column, multiple row ranges.
--
Never attach files.
Snip unnecessary quoted text.
Never multipost (though crossposting is usually OK).
Don't change subject lines because it corrupts Google newsgroup archives.