Linear Interpolation in VBA

annie_54

New Member
Joined
Jul 22, 2019
Messages
3
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
-------------------------------------------------------------------------------------------------
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
welcome, Annie

Please post a sample of the input data. What values are in what cells, and maybe describe what each value means if it might aid understanding.

And then explain what the result is for those inputs and where/how it will be used.

regards, Fazza
 
Upvote 0
Can you also post the first part of your code - possibly only one line from the top (Public Function, perhaps?
Also, where does this code reside? in a code module, or worksheet module, or ThisWorkbook module?
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top