+ Reply to Thread
Results 1 to 11 of 11

Infinite Loop

  1. #1
    Registered User
    Join Date
    09-11-2007
    Posts
    41

    Infinite Loop

    hello all...

    i'm trying to loop through a bunch of worksheets and copy certain cells and paste it in a master sheet.

    Please take a look at my code below because it keeps copying the same thing over and over and is stuck in an infinite loop.

    Please Login or Register  to view this content.
    Thank you.
    Last edited by phong919; 01-22-2010 at 04:57 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Infinite Loop help

    Hi,

    With 35 posts you really should know the rules about embedding code between Code tags.

    Please correct.

    Rgds
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    09-11-2007
    Posts
    41

    Re: Infinite Loop

    sorry about that. code corrected.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Infinite Loop

    Hi,

    It would be easier to advise with certainty if we had the actual workbook since the loop exit condition in the line below is clearly never being met.

    Please Login or Register  to view this content.
    Try stepping through the macro to observe why the Do never encounters a value in the 2nd (presumably B) column which is not equal to "Issues/Risks Log"

    For instance are the 'Issues/Risks Log' in a different case perhaps, spelled differently or perhaps have a leading/trailing space?

    If you can't debug it, upload the workbook, anonymised if necessary and limited to a representative sample of rows if there are hundreds of them.

    Regards
    Rgds

  5. #5
    Registered User
    Join Date
    09-11-2007
    Posts
    41

    Re: Infinite Loop

    Here is the attached workbook.

    I just checked for the trailing spaces in the do while and it doesn't have any.
    Attached Files Attached Files

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Infinite Loop

    Hi

    In your Case Else statement you are resetting the currentRow variable in the 2nd line to the value 28 i.e.

    Please Login or Register  to view this content.
    So even though you are adding +1 at the end of the Else statement the currentrow variable never reaches the value 37 which is the Loop exit condition.

    Rgds

  7. #7
    Registered User
    Join Date
    09-11-2007
    Posts
    41

    Re: Infinite Loop

    what would be the best way of doing it. i removed the

    currentRow = rFindw.Row + 1

    and it doesn't run correctly. The loop takes the actual header on line 28 and not the value in line 29.

    Thanks

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Infinite Loop

    Hi,

    Commenting out that line seems to work fine on the copy I have. The currentrow variable processes until it reaches the value 37 where it exits the Do..Loop and goes on to the next Worksheet if there are any.

    What makes you think it's not working? Have you tried stepping through it line by line to observe what happens?

    Regards

  9. #9
    Registered User
    Join Date
    09-11-2007
    Posts
    41

    Re: Infinite Loop

    Yeah i did the same and it loops through the data but it's missing some column values that i don't see. maybe there's something wrong with my excel application?

  10. #10
    Registered User
    Join Date
    09-11-2007
    Posts
    41

    Re: Infinite Loop

    i'm missing all the column values for

    dest.Range("L" & cursor).Value = ActiveSheet.name

    at the end of the loop.

  11. #11
    Registered User
    Join Date
    09-11-2007
    Posts
    41

    Re: Infinite Loop

    actually i figured it out. there was a couple of columns being deleted towards the end. DUH! thank you for your assistance.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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