+ Reply to Thread
Results 1 to 26 of 26

Error 6 Overflow on Folder Loop

  1. #1
    Registered User
    Join Date
    06-21-2018
    Location
    Calgary, AB
    MS-Off Ver
    2013
    Posts
    94

    Error 6 Overflow on Folder Loop

    First of all - I would like to apologize RIGHT off the bat.

    I am new to VBA and have kind of been winging it - I've been fairly successful, but I know I'm very inefficient and have a billion things to learn.

    I'm trying to loop through a folder and run this code on all files in a folder. The code worked fine on individual files, but it's giving me overflow or out of range errors with the loop. I'm sure it has to do with the way that I have my integer loops set up.

    Please be gentle. I know it's not great, I'm just trying to learn.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,913

    Re: Error 6 Overflow on Folder Loop

    What happens if you declare variables as Long instead of Integer?

    Integer can only hold values between... -32,768 to 32,767 (2 bytes)
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    06-21-2018
    Location
    Calgary, AB
    MS-Off Ver
    2013
    Posts
    94

    Re: Error 6 Overflow on Folder Loop

    Forgive my ignorance - I can do that and still run as a loop with arithmetic?

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,913

    Re: Error 6 Overflow on Folder Loop

    Yes. Long is basically 4 bytes version of integer and limit is around 2mil.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,607

    Re: Error 6 Overflow on Folder Loop

    See if this change works
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-21-2018
    Location
    Calgary, AB
    MS-Off Ver
    2013
    Posts
    94

    Re: Error 6 Overflow on Folder Loop

    I made this change but I then get a compile error for expected array.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,607

    Re: Error 6 Overflow on Folder Loop

    Compile Error?

    You have some variables not declared.

    Add one line on the top of module
    Please Login or Register  to view this content.
    And do a step debug.

  8. #8
    Registered User
    Join Date
    06-21-2018
    Location
    Calgary, AB
    MS-Off Ver
    2013
    Posts
    94

    Re: Error 6 Overflow on Folder Loop

    I ran that and nothing is coming up as not defined, but at

    Please Login or Register  to view this content.
    I am getting a compile error for expected array

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,607

    Re: Error 6 Overflow on Folder Loop

    Then you didn't add that line.

    If I run your code with that line on the top of the module, it doesn't compile due to undeclared variables

    Debug.Print Workbook
    CampAccom = "CC30000"
    travel = "CC_Travel / Entertainment"
    meals = "CC_Meals"

  10. #10
    Registered User
    Join Date
    06-21-2018
    Location
    Calgary, AB
    MS-Off Ver
    2013
    Posts
    94

    Re: Error 6 Overflow on Folder Loop

    You're correct - I'm not awake enough and apparently added it above the sub. Give me a moment to fix those variables and try again

  11. #11
    Registered User
    Join Date
    06-21-2018
    Location
    Calgary, AB
    MS-Off Ver
    2013
    Posts
    94

    Re: Error 6 Overflow on Folder Loop

    I defined all those variables and correctly placed the option explicit statement and I'm still getting the same error

  12. #12
    Registered User
    Join Date
    06-21-2018
    Location
    Calgary, AB
    MS-Off Ver
    2013
    Posts
    94

    Re: Error 6 Overflow on Folder Loop

    Is it potentially because a and b are defined as integers, whereas result1 is defined as long?

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,607

    Re: Error 6 Overflow on Folder Loop

    If the error is Overflow, it would be a variable type.

    Why are you define Integer?, there is no advantage for it, AFAIK, so I always use Long anyway.

  14. #14
    Registered User
    Join Date
    06-21-2018
    Location
    Calgary, AB
    MS-Off Ver
    2013
    Posts
    94

    Re: Error 6 Overflow on Folder Loop

    Will check that and try again, thank you

  15. #15
    Registered User
    Join Date
    06-21-2018
    Location
    Calgary, AB
    MS-Off Ver
    2013
    Posts
    94

    Re: Error 6 Overflow on Folder Loop

    It's still pulling that error and I have zero idea why

    Edit: It's not giving an overflow error. It's saying

    Compile error: Expected array

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,607

    Re: Error 6 Overflow on Folder Loop

    Since you are the only one who can actually test the code,
    While you are in VBE, Go to [View] - [Local Window]
    Then run the code.
    When the code get into debug mode, see local window and find variable "result1" and see what's happening.

  17. #17
    Registered User
    Join Date
    06-21-2018
    Location
    Calgary, AB
    MS-Off Ver
    2013
    Posts
    94

    Re: Error 6 Overflow on Folder Loop

    I apologize again for my naivety. I did bring up the locals window, but nothing is popping up in the window when I run the code.

    I did, however, comment out the line with result1 and run it again, and I received the same error for result2.

  18. #18
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,607

    Re: Error 6 Overflow on Folder Loop

    That's really strange.

    Just try change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    and add 1 line right after last dim statement
    Please Login or Register  to view this content.
    And see what happens.

    If it still give you an error, I suggest you to create a new workbook...

  19. #19
    Registered User
    Join Date
    06-26-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    Re: Error 6 Overflow on Folder Loop

    When you get the compile error, does the VB editor highlight a particular line of code? If so, which line?

  20. #20
    Registered User
    Join Date
    06-21-2018
    Location
    Calgary, AB
    MS-Off Ver
    2013
    Posts
    94

    Re: Error 6 Overflow on Folder Loop

    It's running (seemingly) perfectly now - my only other question is that even though I have disabled alerts, I still get popups pertaining to updating links and data sources. What would be my best way to auto-accept these?

    Thank you both so much for your help. As I am new here, please advise if I need to open a separate thread for that question. I figured it would be acceptable here since my code is already listed.

    *EDIT*

    It appears to have gone out of range - The culprit line being

    Please Login or Register  to view this content.
    I suppose we have again exceeded the integer limit.
    Last edited by visualnotsobasic; 06-28-2018 at 12:46 PM.

  21. #21
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,607

    Re: Error 6 Overflow on Folder Loop

    1) Did you change Integer to Long?

    2) change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  22. #22
    Registered User
    Join Date
    06-21-2018
    Location
    Calgary, AB
    MS-Off Ver
    2013
    Posts
    94

    Re: Error 6 Overflow on Folder Loop

    Thanks for the notification solution.

    I changed the integers for the given letters (a/b/n/i) to long
    When I change the "result1" and "result2" to long, I get the compile error at the location stated earlier.

  23. #23
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,607

    Re: Error 6 Overflow on Folder Loop

    No.... You should not change the type of arrays.
    Leave them as they are and change only a,b,n and i

  24. #24
    Registered User
    Join Date
    06-21-2018
    Location
    Calgary, AB
    MS-Off Ver
    2013
    Posts
    94

    Re: Error 6 Overflow on Folder Loop

    Yes, I ran it that way and it eventually went out of range. Should I expand the range of result1 and result2?

  25. #25
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,607

    Re: Error 6 Overflow on Folder Loop

    OK, expand the array like 1 to 200000 or whatever you think it is more than enough.

  26. #26
    Registered User
    Join Date
    06-21-2018
    Location
    Calgary, AB
    MS-Off Ver
    2013
    Posts
    94

    Re: Error 6 Overflow on Folder Loop

    I put it up to 2000000 which I'm sure is awful practice, but the whole thing worked. Thank you very much.

+ 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. Replies: 0
    Last Post: 05-24-2016, 12:32 PM
  2. [SOLVED] Loop through files in folder ERROR
    By anrichards22 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-20-2016, 07:45 AM
  3. Replies: 12
    Last Post: 03-09-2015, 05:52 PM
  4. [SOLVED] Overflow error in middle of processing loop
    By davidmhcampbell in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-23-2014, 12:35 PM
  5. [SOLVED] OverFlow Error in For Loop
    By Excel_Fan in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-28-2014, 02:43 PM
  6. 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
  7. 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

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