+ Reply to Thread
Results 1 to 11 of 11

VBA overflow error

  1. #1
    Registered User
    Join Date
    06-15-2020
    Location
    Eindhoven
    MS-Off Ver
    2016
    Posts
    19

    VBA overflow error

    Hello,

    Ik have this vba-code:
    Please Login or Register  to view this content.
    The value in Range("AG1") changes every time, because it's a sumformula who calculates differences in values between cells.

    The vba-code is working well, but when i put some more formulas in different cells, then I got some error:
    Please Login or Register  to view this content.
    The error goes to:
    Please Login or Register  to view this content.
    When I delete some formulas in the worksheet, the code is running well.

    What do I need to change in the vba-code, to prevent the overflow error?

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,757

    Re: VBA overflow error

    What is the value of arrBytes(i, j) when this error occurs?

  3. #3
    Registered User
    Join Date
    06-15-2020
    Location
    Eindhoven
    MS-Off Ver
    2016
    Posts
    19

    Re: VBA overflow error

    Quote Originally Posted by 6StringJazzer View Post
    What is the value of arrBytes(i, j) when this error occurs?
    In the range are a lot of Hex decimals that changes when the values in others worksheet changes too.

    There are some worksheets with values and the vba-code has to calculate Range("AG1") everytime. When Range("AG1") has some value, the loop has to stop and run the vba-code to create the file with the Hex-decimals.
    Last edited by Schiavoni; 08-31-2020 at 02:41 PM.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,869

    Re: VBA overflow error

    When it errors, what value is in AG1? Any chance it represents a number larger than 255? According to the documentation (https://docs.microsoft.com/en-us/off...byte-data-type ), the Byte data type stores numbers from 0 to 255, and returns the overflow error if the number is outside of that range.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Registered User
    Join Date
    06-15-2020
    Location
    Eindhoven
    MS-Off Ver
    2016
    Posts
    19

    Re: VBA overflow error

    The value is under 200. I already have deleted some formulas in a worksheet and now the vba-code is working. The formulas I add to the worksheet, don't affect the value in AG1. When I add them, I got the overflow error. The vba-code created some files before the overflow error appears and stops running the code.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,757

    Re: VBA overflow error

    Aside from your error, this syntax is a little strange (but legal) and I am guessing it does not do what you think it does. Can you describe what you want to check for here?

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-15-2020
    Location
    Eindhoven
    MS-Off Ver
    2016
    Posts
    19
    Quote Originally Posted by 6StringJazzer View Post
    Aside from your error, this syntax is a little strange (but legal) and I am guessing it does not do what you think it does. Can you describe what you want to check for here?

    Please Login or Register  to view this content.
    When the value of AG1 is equal and between 40 and 80, the vba-code has to go further, otherwise the worksheet has to calculate again and loop.
    In some cells I have a formula:
    Please Login or Register  to view this content.
    When 10 cells changes values, the total of the changes is in AG1. When this value is between 40 and 80, the vba-code has to run after the loop, otherwise calculate again.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,757

    Re: VBA overflow error

    In that case the expression is incorrect. The expression you are using always evaluates to TRUE and will always exit the loop after the first time. You want this.

    Loop Until Range("AG1").Value >= 40 And Range("AG1").Value <= 80

  9. #9
    Registered User
    Join Date
    06-15-2020
    Location
    Eindhoven
    MS-Off Ver
    2016
    Posts
    19

    Re: VBA overflow error

    Quote Originally Posted by 6StringJazzer View Post
    In that case the expression is incorrect. The expression you are using always evaluates to TRUE and will always exit the loop after the first time. You want this.

    Loop Until Range("AG1").Value >= 40 And Range("AG1").Value <= 80
    Thanks for the answer, but it isn't working. I've added some extra formulas in the worksheet and changes the Loop-code, but I get the overflow error again. When I don't add the extra formulas, I don't get an error.

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,757

    Re: VBA overflow error

    Quote Originally Posted by Schiavoni View Post
    Thanks for the answer, but it isn't working. I've added some extra formulas in the worksheet and changes the Loop-code, but I get the overflow error again. When I don't add the extra formulas, I don't get an error.
    The change to the Loop code is completely unrelated to the overflow error. It's a logic error that I noticed.

    If adding and removing formulas causes and resolves an overflow error, then there is a problem that we can't solve just by looking at code. If you attach your file and identify which formulas you removed we can diagnose the overflow problem.

  11. #11
    Registered User
    Join Date
    06-15-2020
    Location
    Eindhoven
    MS-Off Ver
    2016
    Posts
    19

    Re: VBA overflow error

    I've found what was wrong with the formulas. Some values turned below zero and can't be converted to Hex-decimals. So, I've changed that and now the code is working well.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Ribbon Customization error (Long Data Type but still overflow error)
    By ImranBhatti in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-30-2018, 08:15 AM
  2. [SOLVED] Overflow error?
    By danielexcelvba in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 07-11-2017, 03:47 PM
  3. Overflow error
    By VelvetRevolver84 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-23-2013, 11:50 PM
  4. Overflow error, can't see why
    By Alexander_V in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-18-2012, 11:57 AM
  5. Explanation of the Run-time error '6': Overflow Error
    By mgphill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-25-2012, 10:46 AM
  6. Want to do a while-loop but get error message: run error '6' overflow
    By danzi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2011, 01:48 PM
  7. [SOLVED] vba error 6 overflow
    By tinybears in forum Excel General
    Replies: 3
    Last Post: 05-02-2006, 05:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1