Excel VBA to lookup rows using multiple conditions

sukru

New Member
Joined
Oct 19, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello,

I would like to write excel vba codes to help me find some values in an Excel table and do an interpolation between the values. I tried Bard, but I couldn't get it to understand what i need. Your help is very much appreciated.
I have a lookup table like this:
ABResult
180​
29.2035​
0.100001​
180​
29.884​
0.199999​
180​
33.5401​
0.299989​
180​
38.6137​
0.400004​
180​
44.6787​
0.499991​
200​
31.2836​
0.100001​
200​
31.7116​
0.199999​
200​
35.0952​
0.299989​
200​
39.8694​
0.400004​
200​
45.609​
0.499991​
220​
33.2044​
0.100001​
220​
33.4297​
0.199999​
220​
36.5857​
0.299989​
220​
41.1143​
0.400004​
220​
46.5736​
0.499991​
240​
34.9716​
0.100001​
240​
35.0398​
0.199999​
240​
38.0141​
0.299989​
240​
42.3263​
0.400004​
240​
47.566​
0.499991​

I will enter Parameter A and Parameter B.
The code needs to find the rows where the first column values are closest to Parameter A. For example, if Parameter A = 210, it should find all the rows where the 1st column is equal to 200 and 220.
Then for each of these set of rows (first set is where the 1st column is equal to 200 and the second set is where the 1st column is equal to 220), the code should find the two closest numbers to Parameter B, and return the value in column 3 (Result column).
So there should be 4 outputs at this point.

Then the code should do an interpolation between the two outputs in each set, so that it gives 1 output for each set... and then it should do another interpolation to find the value corresponding to the actual Parmeter A.
Eventually there needs to be 1 output value.

If Parameter A or Parameter B are exactly equal to the values in column 1 or column 2 of the lookup table, then no need to do an interpolation.

Can you help me with this task please?

Thanks!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
1. depending on your data, add another column that is Column A *1000 + Column B.
2 do a match using that new column (I forget either the 1 or -1 parameter) to find the closest one below the data (watch out for if the value is Below the lowest one)
3. Add 1 to that match
4. Now you have the the rows.
5. Take the data from each of those 2 data points
6 Now just extrapolate

There are more complicated lookups you can do, but this is simpler
 
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