VBA code to interpolate values between two worksheets

brandon20

Board Regular
Joined
Feb 12, 2014
Messages
203
Hi,

I have a question that is kinda complected. But can definitely be done in VBA.

I have data that gives a well name and a depth in one worksheet, and I have other data that gives a well name and a depth in the other worksheet.

The second worksheet has Surfaces associated with its depths. The first worksheet has pressures associated with its depths.
The pressure depths are rarely exactly equal to the well top depths but the pressure depths always fall within the interval of the shallower surface to the deeper surface.

What I need is to fill a column with the Surface name associated with its pressure depth. (ie, if a specific wells pressure falls within that wells surface interval I need that pressure to have the name of the shallower surface.)

As seen below it is a little easier to understand. The first excel sheet is the well, MD, and Surface. The second sheet is the Well, MD, Pressure, (THEN it has a surface column which I filled in two surfaces that would show up if the VBA code ran.) As you can see, Z51CH is at a depth of 9220 in the second worksheet, this is because that depth falls between Z51CH (9204.9) and Z51 (9232.9).


Well
MD
Surface
RA-0074
9204.9
Z51CH
RA-0074
9232.9
Z51
RA-0074
9237.3
Z48CH
RA-0074
9250.93
Z48
RA-0074
9313.2
Z46CH
RA-0074
9415.6
Z46

<tbody>
</tbody>

Well identifier
MD
FPRESS
SURFACE
RA-0074
8953
4185.8
RA-0074
9000
4220
RA-0074
9028
4245
RA-0074
9110
4292
RA-0074
9165
4244.7
RA-0074
9166
4244.6
RA-0074
9182
4220.4
RA-0074
9220
4238.1
Z51CH
RA-0074
9350
4270.5
Z46CH
RA-0074
9447
4312
RA-0074
9539
4352
RA-0074
9570
4372.8
RA-0074
9641
4539
RA-0074
9666
4834

<tbody>
</tbody>
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,215,053
Messages
6,122,888
Members
449,097
Latest member
dbomb1414

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