Guys,
I'm running Excel 2003 on XP Pro and I'm having a problem with the code below. I'm trying to calculate either Heat reqd in kw or Outlet temp in deg. The two separate sections of code run fine on their own but I think I have the loop in the wrong place. I want the code to calculate one or the other depending on what data is available within the test table i.e. if there is NO kw heating power, calc heat reqd (kw) to give me the stated outlet temp or if there IS kw heating power, calc the outlet temp that can be achieved from this energy. Unfortunately due to restrictions on my networked PC I cant post the table in HTML format. Thanks in advance.
Sorry ...... here it is in code form.
I'm running Excel 2003 on XP Pro and I'm having a problem with the code below. I'm trying to calculate either Heat reqd in kw or Outlet temp in deg. The two separate sections of code run fine on their own but I think I have the loop in the wrong place. I want the code to calculate one or the other depending on what data is available within the test table i.e. if there is NO kw heating power, calc heat reqd (kw) to give me the stated outlet temp or if there IS kw heating power, calc the outlet temp that can be achieved from this energy. Unfortunately due to restrictions on my networked PC I cant post the table in HTML format. Thanks in advance.
Sorry ...... here it is in code form.
Code:
Function HeatInTable()
'Application.ScreenUpdating = False
' this routine will calculate heat reqd(kw) or outlet temp in degC
' the input reqd are all metric
' list of all variables used
Dim A, B, c, D, E1, E2, E3, E4, E5, E6, P1, P2 As Variant
Dim HEAT, Q, Tin, H1in, ERFin, ENTHIN, Tout As Variant
Dim H1out, ERFout, ENTHOUT, DELTAH, MOL As Variant
' set parameters
A = -0.00792078
B = 950.85
c = 0.0314566
D = 0.000009138
E1 = 0.000358
E2 = 0.001391
E3 = 0.0003572
E4 = 0.000008397
E5 = 0.00000119
E6 = 0.0845
MOL = 17.18 'molecular weight of gas
' calc all variables
If IsEmpty(Range("I12").Offset(0, 6)) = True Then
For R = 12 To 25
Range("I" & R).Select
P1 = Range("I" & R).Offset(0, 1) + 14.7 ' inlet pressure
P2 = Range("I" & R).Offset(0, 2) + 14.7 ' outlet pressure
Q = Range("I" & R).Offset(0, 3) * (MOL / 3) / 28.31682051 'calc and conversion to Kscmh
Tin = Range("I" & R).Offset(0, 4) + 273.15 'inlet temperature
H1in = (c - E1) * Tin + D * (Tin ^ 2) + (A - E2) * P1 - B * P1 / (Tin ^ 2)
ERFin = -E3 * (P1 ^ 2) + E4 * P1 * Tin + E5 * Tin * (P1 ^ 2) + E6
ENTHIN = H1in + ERFin
Tout = Range("I" & R).Offset(0, 5) + 273.15
H1out = (c - E1) * Tout + D * (Tout ^ 2) + (A - E2) * P2 - B * P2 / (Tout ^ 2)
ERFout = -E3 * (P2 ^ 2) + E4 * P2 * Tout + E5 * Tout * (P2 ^ 2) + E6
ENTHOUT = H1out + ERFout
DELTAH = ENTHIN - ENTHOUT ' enthalpy difference
' calculate heat reqd in Kw's
HEAT = Int(-DELTAH * Q * (1000 / MOL))
Range("I" & R).Offset(0, 7) = HEAT
Next
ElseIf IsEmpty(Range("I12").Offset(0, 7)) = True Then
For R = 12 To 25
Range("I" & R).Select
Dim Check, Counter
Check = True: Counter = -20 ' Initialize variables.
Do While Counter < 25
Counter = Counter + 0.1 ' Increment Counter.
P1 = Range("I" & R).Offset(0, 1) + 14.7 ' inlet pressure
P2 = Range("I" & R).Offset(0, 2) + 14.7 ' outlet pressure
Q = Range("I" & R).Offset(0, 3) * (MOL / 3) / 28.31682051 'calc and conversion to Kscmh
Tin = Range("I" & R).Offset(0, 4) + 273.15 'inlet temperature
H1in = (c - E1) * Tin + D * (Tin ^ 2) + (A - E2) * P1 - B * P1 / (Tin ^ 2)
ERFin = -E3 * (P1 ^ 2) + E4 * P1 * Tin + E5 * Tin * (P1 ^ 2) + E6
ENTHIN = H1in + ERFin
Tout = Counter + 273.15 ' Outlet Temp
H1out = (c - E1) * Tout + D * (Tout ^ 2) + (A - E2) * P2 - B * P2 / (Tout ^ 2)
ERFout = -E3 * (P2 ^ 2) + E4 * P2 * Tout + E5 * Tout * (P2 ^ 2) + E6
ENTHOUT = H1out + ERFout
DELTAH = ENTHIN - ENTHOUT ' enthalpy difference
' calculate outlet temp in deg's
HEAT = Int(-DELTAH * Q * (1000 / MOL))
Range("I" & R).Offset(0, 5) = Tout - 273.15 'display the outlet temp
If Int(HEAT) > Range("I" & R).Offset(0, 6) Then ' If condition is True.
Check = False ' Set value of flag to False and exit loop
Exit Do
End If
Loop
Next
End If
'Application.ScreenUpdating = True
End Function