+ Reply to Thread
Results 1 to 6 of 6

OverFlow Error in For Loop

  1. #1
    Registered User
    Join Date
    08-07-2009
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    OverFlow Error in For Loop

    First-time poster here. I used to have a ton of experience with Java and C# but now my job calls for VB scripts in excel. Probably an assignment error or logic error but here's the code :

    basically what im doing is i have two workbooks "New Dashboard" and "Book1". I search column A in Book1 for HELLO, and then i use the row it was found in to grab a value "HrsVal". I take that value and i put it "New Dashboard". I then do the same for every sheet. It seems to fail in my second loop in the 2nd sheet. Error says "Overflow".


    Please Login or Register  to view this content.
    Thanks

  2. #2
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: OverFlow Error in For Loop

    You get an overflow error most likely because the maximum value of a VBA Integer has been exceeded (+32,767). Try dimensioning RowNumber as a Long and see if this rectifies your problem.

    Richard
    Richard Schollar
    Microsoft MVP - Excel

  3. #3
    Registered User
    Join Date
    08-07-2009
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: OverFlow Error in For Loop

    Quote Originally Posted by RichardSchollar View Post
    You get an overflow error most likely because the maximum value of a VBA Integer has been exceeded (+32,767). Try dimensioning RowNumber as a Long and see if this rectifies your problem.

    Richard

    I have 3 sheets, and the RowNumber values will be 13 in the first loop, 35 in the 2nd, and 14 in the 3rd (i have test sheets setup). I tried long. Still get the same OverFlow.


    Thanks!


    You're right... the value of HrsValue was over 32767... it was 70,000! Long fixed it. Thanks!

    This is SOLVED. Is there a way to mark this solved?
    Last edited by Excel_Fan; 08-09-2009 at 01:56 PM.

  4. #4
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: OverFlow Error in For Loop

    If you double-click on the title bar when viewing the forum you should be able to amend the title to SOLVED: at the front (this is how the forum software works on another web forum I frequent - things may be different here though)

  5. #5
    Registered User
    Join Date
    08-07-2009
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: OverFlow Error in For Loop

    Quote Originally Posted by RichardSchollar View Post
    If you double-click on the title bar when viewing the forum you should be able to amend the title to SOLVED: at the front (this is how the forum software works on another web forum I frequent - things may be different here though)
    great. done. thanks!

  6. #6
    Registered User
    Join Date
    09-28-2012
    Location
    boston
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: OverFlow Error in For Loop

    You are exactly correct. I changed to a Long and it works. You rock. Tracy

+ 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. 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
  2. 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
  3. Msg error (overflow)
    By Mamud in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-25-2011, 10:54 AM
  4. Overflow Error
    By narrowgate88 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-10-2010, 02:08 AM
  5. Overflow error, need help
    By mkerstei in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-13-2006, 10:20 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