ENGinTraining
New Member
- Joined
- May 14, 2011
- Messages
- 14
I am attempting to write a code to look up values from a sheet in my excel file. If the input doesn't match exactly to a value in the chart then I want the program to progressively add and subtract 1 from the value until it finds a true value.
Can any first tell me why when I compile it, it gives me an error saying "End If without Block If". Also, if my lookups look correct, this is my first time writing something like this.
Code:
Function sat_state3_v(state3_p As Double, state3_v As Double) As Long
Dim find, find2, Plookup, checkloop As String, checkloop2 As String, new_p As Double, orig_p As Double, orig_p2 As Double, HP_side As Double, LP_side As Double, check As String, check2 As String, High_pressure As Double, Low_pressure As Double, high_temp As Double, low_temp As Double
Dim Table_A5E As Range
Set Table_A5E = Worksheets("A-5E (Sat Water)").Range("A9:F619")
orig_p = Application.WorksheetFunction.VLookup(state3_p, Table_A5E, 2, False)
check = IsError(orig_p)
If check = "True" Then Do
High_pressure = state3_p + 1
HP_side = Application.WorksheetFunction.VLookup(High_pressure, Table_A5E, 2, False)
checkloop = IsError(HP_side)
Loop Until checkloop = "False"
End If
orig_p2 = Application.WorksheetFunction.VLookup(state3_p, Table_A5E, 2, False)
check2 = IsError(orig_p2)
If check2 = "True" Then Do
Low_pressure = state3_p - 1
LP_side = Application.WorksheetFunction.VLookup(Low_pressure, Table_A5E, 2, False)
checkloop2 = IsError(LP_side)
Loop Until checkloop2 = "False"
End If
new_volume = (((state3_p - Low_pressure) / (High_pressure - Low_pressure)) * (HP_side - LP_side) + LP_side)
sat_state3_v = new_volume
Can any first tell me why when I compile it, it gives me an error saying "End If without Block If". Also, if my lookups look correct, this is my first time writing something like this.
Code:
Function sat_state3_v(state3_p As Double, state3_v As Double) As Long
Dim find, find2, Plookup, checkloop As String, checkloop2 As String, new_p As Double, orig_p As Double, orig_p2 As Double, HP_side As Double, LP_side As Double, check As String, check2 As String, High_pressure As Double, Low_pressure As Double, high_temp As Double, low_temp As Double
Dim Table_A5E As Range
Set Table_A5E = Worksheets("A-5E (Sat Water)").Range("A9:F619")
orig_p = Application.WorksheetFunction.VLookup(state3_p, Table_A5E, 2, False)
check = IsError(orig_p)
If check = "True" Then Do
High_pressure = state3_p + 1
HP_side = Application.WorksheetFunction.VLookup(High_pressure, Table_A5E, 2, False)
checkloop = IsError(HP_side)
Loop Until checkloop = "False"
End If
orig_p2 = Application.WorksheetFunction.VLookup(state3_p, Table_A5E, 2, False)
check2 = IsError(orig_p2)
If check2 = "True" Then Do
Low_pressure = state3_p - 1
LP_side = Application.WorksheetFunction.VLookup(Low_pressure, Table_A5E, 2, False)
checkloop2 = IsError(LP_side)
Loop Until checkloop2 = "False"
End If
new_volume = (((state3_p - Low_pressure) / (High_pressure - Low_pressure)) * (HP_side - LP_side) + LP_side)
sat_state3_v = new_volume