Hey Everyone,
I have been working on a function to linear interpolate some data- I got it to where it was giving values however they seem to be incorrect. I cant find an error in the equation so far so i am not sure where to fix things.
I am also extremely new to VBA to bear with me on the code
Thanks for the help in advance!
--------------------------------------------------------------------------------------------------
Dim X1 As Double, X2 As Double, X3 As Double, Y1 As Double, Y3 As Double
ThisWorkbook.Activate
' X1 is used as the smallest x value
Application.ActiveCell.Activate
X1 = ActiveCell.Value
' X is used as the middle value
Application.ActiveCell.offset(1, 0).Activate
X = ActiveCell.Value
' X2 is used as the largst x value
Application.ActiveCell.offset(1, 0).Activate
X2 = ActiveCell.Value
' Y1 is used as the smallest Y value
Application.ActiveCell.offset(-2, 1).Activate
Y1 = ActiveCell.Value2
' Y2 is used as the largest Y value
Application.ActiveCell.offset(2, 0).Activate
Y2 = ActiveCell.Value2
Dim Pt1 As String, Pt2 As String, Pt3 As String
Pt1 = (X - X1)
Pt2 = (Y2 - Y1)
Pt3 = (X2 - X1)
MsgBox "" & Y1 + Pt1 * (Pt2 \ Pt3)
End Function
-------------------------------------------------------------------------------------------------
I have been working on a function to linear interpolate some data- I got it to where it was giving values however they seem to be incorrect. I cant find an error in the equation so far so i am not sure where to fix things.
I am also extremely new to VBA to bear with me on the code
Thanks for the help in advance!
--------------------------------------------------------------------------------------------------
Dim X1 As Double, X2 As Double, X3 As Double, Y1 As Double, Y3 As Double
ThisWorkbook.Activate
' X1 is used as the smallest x value
Application.ActiveCell.Activate
X1 = ActiveCell.Value
' X is used as the middle value
Application.ActiveCell.offset(1, 0).Activate
X = ActiveCell.Value
' X2 is used as the largst x value
Application.ActiveCell.offset(1, 0).Activate
X2 = ActiveCell.Value
' Y1 is used as the smallest Y value
Application.ActiveCell.offset(-2, 1).Activate
Y1 = ActiveCell.Value2
' Y2 is used as the largest Y value
Application.ActiveCell.offset(2, 0).Activate
Y2 = ActiveCell.Value2
Dim Pt1 As String, Pt2 As String, Pt3 As String
Pt1 = (X - X1)
Pt2 = (Y2 - Y1)
Pt3 = (X2 - X1)
MsgBox "" & Y1 + Pt1 * (Pt2 \ Pt3)
End Function
-------------------------------------------------------------------------------------------------