Private Sub Command1_click()
' dada una presión y una temperatura de referencia, el programa selecciona
' un rango de celdas dentro de la tabla, que corresponden a valores para interpolar
' entre dicha presión y temperatura de referencia
Dim ap As New Excel.Application
ap.Workbooks.Open "d:\Pepo\Proyecto VB\tabla para pruebas.xls"
ap.Worksheets("volumen").Select
Dim i As Integer
Dim j As Integer
' Como datos tenemos Tref y Pref
Tref = 0.025
Pref = 35.5
' i es el índice de filas y j el de columnas
For j = 2 To 55
For i = 4 To 79
' Selecciona los datos de la tabla cuyos valores sean los
' inmediatamente inferiores a Pref y Tref
With Range("A1:BC79")
If .Cells(3, j).Value < Tref Then
If .Cells(i, 1).Value < Pref Then
Set T1 = .Cells(3, j)
Set T2 = .Cells(3, j + 1)
Set P1 = .Cells(i, 1)
Set P2 = .Cells(i + 1, 1)
Set v11 = .Cells(i, j)
Set v12 = .Cells(i, j + 1)
Set v21 = .Cells(i + 1, j)
Set v22 = .Cells(i + 1, j + 1)
End If
End If
End With
Next i
Next j
' Interpola el volúmen específico "v" entre los valores de temperatura y los de presión
va = v12 - (v12 - v11) * (T2 - Tref) / (T2 - T1)
vc = v22 - (v22 - v21) * (T2 - Tref) / (T2 - T1)
v = vc - (vc - va) * (P2 - Pref) / (P2 - P1)
' muestra en pantalla el valor intermpolado, correspondiente a los datos de Pref y Tref
TxtCeldas.Text = v
ap.Quit
Set ap = Nothing