VBA Overflow Error

  • 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.


  • Re: VBA Overflow Error


    Hi,


    The "overflow" error usually means that the number is too big for the data type...
    What are the value of w and Tr when you get the error?


    Note that you declare 2 variables Alpha at the beginning, one as Double, the other as Variant. The error probably come from there...

  • Re: VBA Overflow Error


    The value for w is a constant 0.085, Tr is calculated from T (constant 45) and Tc 9.3. Tr is T/Tc so about 5, but not a number I would expect to get an overflow error from.


    And yes, I noticed that when I posted this I did have 2 lines about alpha, but I had been going back and forth between Dim statements, and commenting one out, and both options had given me the same error. I also took away the Option Explicit statement, and left Alpha undefined, and it gave me the same error.

  • Re: VBA Overflow Error


    Quote from pike;658338

    can you give example values for

    Code
    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)


    DT = 25
    R = 83.14
    w = 0.085
    Mw = 28.1
    Pstart = 10
    Pstop = 120
    DP = 10


    I had a friend mention that this problem might be due to the fact that I had not loaded a value for Tc and Pc into the program prior to trying to use it in the formula, and thus the code was confused by a lack of value. I am planning on checking that when I get access to my program again (I only have access to a read only version of excel at this point in time).

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!