Public Function Linear2d(x As Double, y As Double, tb As Range)
Dim i, j As Long
Dim x1, x2, y1, y2, q11, q12, q21, q22, q1, q2 As Double
' tra theo chieu doc
i = 3
Do While (tb.Cells(i, 1) < x) And (i < tb.Rows.Count)
i = i + 1
Loop
i = i - 1
' tra theo chieu ngang
j = 3
Do While (tb.Cells(1, j) < y) And (j < tb.Columns.Count)
j = j + 1
Loop
j = j - 1
' tinh gia tri cac diem
x1 = tb.Cells(i, 1)
x2 = tb.Cells(i + 1, 1)
y1 = tb.Cells(1, j)
y2 = tb.Cells(1, j + 1)
q11 = tb.Cells(i, j)
q12 = tb.Cells(i, j + 1)
q21 = tb.Cells(i + 1, j)
q22 = tb.Cells(i + 1, j + 1)
' noi suy duong dung
q1 = q11 + (x - x1) * (q21 - q11) / (x2 - x1)
q2 = q12 + (x - x1) * (q22 - q12) / (x2 - x1)
' noi suy duong ngang
Linear2d = q1 + (y - y1) * (q2 - q1) / (y2 - y1)
End Function