Hello, I have been working on a code that is supposed to calculate values for gas density. I know my code needs some cleaning up, but before I clean it up, I wanted to make sure it would run. The Debugging does not show any errors, but when I run the code, I get an overflow error. I'm still very new to VBA Macro Coding, but my understanding of the Overflow error is that it means I have a term incorrectly dimensioned. I saw lots of information about how this is related to integers, and to change the type to long, however the error is showing up on a line where the terms are set to Double. I'm posting below section of code that is giving me the error, along with all the code that comes before it. I'm leaving out the code below, but I can add more if you need it.
Thank you for your help.
Option Explicit '13a
Dim N As Integer '13b
Dim T As Single, Tstart As Single
Dim Z As Double
'************************
Dim DT As Single
Dim Tc As Single
Dim Tr As Single
'************************
Dim R As Single
Dim w As Single
Dim Mw As Double
Dim B As Double
Dim Alpha As Double
Dim Alpha As Variant
Dim A As Single
Dim AA As Single
Dim BB As Single
Dim RA1 As Single
Dim RA2 As Single
Dim RA3 As Double
Dim RA4 As Double
'************************
Dim Pstart As Single
Dim Pstop As Single
Dim DP As Single
Dim P As Double
Dim Pc As Double
Dim D As Double
Dim rowcount As Integer
'************************
Dim Chem As String
'************************
' a line of stars separates sections of code that may need to be rearranged for better flow
Sub PREoS()
'13c clear cells out
Call clear
'Plug constants from worksheet into program
Tstart = Cells(2, 2)
DT = Cells(3, 2)
'************************
R = Cells(5, 2)
w = Cells(10, 2)
Mw = Cells(11, 2)
'************************
Pstart = Cells(2, 4)
Pstop = Cells(3, 4)
DP = Cells(4, 4)
'************************
'Calculate PREoS Values
B = 0.0778 * R * Tc / Pc
Tr = T / Tc
Alpha = (1 + (0.37464 + 1.54226 * w - 0.26992 * w ^ 2) * (1 - Tr ^ 0.5)) ^ 2 ****THIS IS THE LINE THAT IS HIGHLIGHTED WITH OVERFLOW ERROR****
A = 0.45724 * (R ^ 2) * (Tc ^ 2) / Pc * Alpha
AA = A * P / ((R ^ 2) * (T ^ 2))
BB = B * P / (R * T)
'Set values to be plugged into FindZ
RA1 = 1
RA2 = BB - 1
RA3 = AA - (2 * BB) - (3 * BB ^ 2)
RA4 = BB ^ 3 + BB ^ 2 - (AA * BB)
Display More