Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Access VBA Linear Interpolation 1

Status
Not open for further replies.

yabby24

Chemical
Nov 2, 2015
10
0
0
US
I am trying to use Access VBA code to interpolate (linearly) and return values to a table. I am still very new to both Access and VBA coding, so please be kind and clear any responses--I appreciate it!

Going off of this formula: y2 = [(x2-x1)(y3-y1)/(x3-x1)] +y1

My x2 column is in a table called "Calculation Sheet", while my x1, x3, y1, and y3 values are in a table called "Lookup Table" (x1,x3 in the same column in increments of 50, y1 and y3 in another column). I am trying to get the Access VBA program to find the y2 value from interpolation "Lookup Table" and return the value back to "Calculation Sheet" in another column for y2, which corresponds to x2 values.

I am at a loss for how to execute something like this and what the best way would be (sub vs function, SQL vs VBA code, etc). Any assistance appreciated, thank you!
 
Replies continue below

Recommended for you

hi,

My x2 column is in a table called "Calculation Sheet", while my x1, x3, y1, and y3 values are in a table called "Lookup Table"

So how does x[sub]2[/sub] relate to your lookup table? I'd GUESS that x[sub]2[/sub] are values between x[sub]1[/sub] and x[sub]3[/sub]
x1,x3 in the same column in increments of 50

I'm an Excel guy much more than an Access guy. I'd be apt to query the table from Excel and do the interpolation in an Excel sheet

So you'd have a column like...
[pre]
X-Values Y-Values
1
10
20
30
40
50
[/pre]
...where 1 and 50 are values from Lookup Table and 10-40 are values from Calculation Sheet.

Unfortunately, you have supplied no other data: No Lookup Table values nor Calculation Sheet values.



Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Hi Skip,

Yes, my x2 values are between x1 and x3.

Let me provide some sample data, sorry about that:

x values (lookup)-----y values (lookup)

1820100------20000
1820150------ 19250
1820200------ 18500
1820250------ 18250
1820300------ 18000

and say my sample x2 value is 1820122.
 
Did you mean that your intermediate x value is 18[highlight #FCAF3E]2[/highlight]0122 not 180122

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
1) I created a Structured Table using your data, named LkupTbl...
[pre]
X-Values Y-Values

1820100 20000
1820150 19250
1820200 18500
1820250 18250
1820300 18000
[/pre]

2) I broke the formula down into factors...
[pre]
x2_ 1820122
match Row 1 =MATCH(x2_,LkupTbl[X-Values],1)
x2_x1 22 =x2_-INDEX(LkupTbl[X-Values],match_Row)
y3_y1 -750 =INDEX(LkupTbl[Y-Values],match_Row+1)-INDEX(LkupTbl[Y-Values],match_Row)
x3_x1 50 =INDEX(LkupTbl[X-Values],match_Row+1)-INDEX(LkupTbl[X-Values],match_Row)
y1_ 20000 =INDEX(LkupTbl[Y-Values],match_Row)
y2_ 19670 =x2_x1*y3_y1/x3_x1+y1_
[/pre]

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Is this for school? Why do you need to use VBA? Why can't you use the worksheet functions?

TTFN
I can do absolutely anything. I'm an expert!
faq731-376 forum1529
 
Yes I meant 1820122. Thanks for pointing that out, and thanks for giving me something to translate into Access! I'll have to work the syntax a bit but otherwise it makes sense!

I've finished school so this is not an assignment. I'm trying to learn VBA coding in an Access environment.
 
Status
Not open for further replies.
Back
Top