Interpolate missing values

I have a four-column table where the 1st column is the independent variable. Each other column has several values missing. Can I ask Calc to interpolate them?

SUB INTERPOLATE
DIM FY&, S AS OBJECT, V#, PY&, FT#, DT#, PV#, T#, C&, L&
LET C& = &O3
SET S = THISCOMPONENT. SHEETS (&O4)
LET FY& = &O1
LET L& = C& + &O4
DO
REM @SCAN 
LET FT# = S. GETCELLBYPOSITION (&O0, FY&). VALUE#
IF FT# = &O0 THEN EXIT DO
LET V# = S. GETCELLBYPOSITION (C&, FY&). VALUE#
IF V# THEN 
REM ?HASTEMP Y
LET S. GETCELLBYPOSITION (L&, FY&). VALUE# = V#
IF PY& THEN
REM ?NOTFIRST Y
LET PV# = S. GETCELLBYPOSITION (C&, PY&). VALUE#
LET DT# = FT# - S. GETCELLBYPOSITION (&O0, PY&). VALUE#
LET PY& = PY& + &O1
DO WHILE PY& < FY&
REM @BLANKS
LET T# = FT# - S. GETCELLBYPOSITION (&O0, PY&). VALUE#
LET S. GETCELLBYPOSITION (L&, PY&). VALUE# = (PV# * T# + V# * (DT# - T#)) / DT#
LET PY& = PY& + &O1
LOOP
REM @BLANKS X
ELSE
REM ?NOTFIRST N
LET PY& = FY&
END IF
REM ?NOTFIRST
END IF
REM ?HASTEMP
LET FY& = FY& + &O1
LOOP
REM @SCAN X
MSGBOX FY&
END SUB
REM !INTERPOLATE X

Assumptions:

  • The table to interpolate is in sheet #5.
  • The independent column is A and data start at row 2.
  • The code below interpolates column D, change C& to interpolate another column.
  • Change L& to put the results further to the right.

How do you use this?