+ Reply to Thread
Results 1 to 5 of 5

Macro goes into an infinite loop

  1. #1
    Forum Contributor
    Join Date
    06-28-2010
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    101

    Macro goes into an infinite loop

    There are two sheets in the workbook. First sheet has certain values in a number of rows in a column. The second sheet also has values in each row in repeating patterns in a column. Like this:

    Please Login or Register  to view this content.
    The macro is supposed to go through each row in Sheet2 per each row in the first sheet; assign a certain value to a variable when any given row in Sheet2 includes some other certain values; compare this variable's value to the row value in Sheet1 and quit once this process has been repeated for 4 rows in Sheet1:

    Please Login or Register  to view this content.
    This is supposed to stop once the match for the 3rd row in Sheet1 is found in Sheet2 but it only happens for the 1st row in Sheet1 and then goes into infinite loop.

    I am very confused. Supposed to be that once a match for the first row of Sheet1 is made, dRow is incremented by 1 and thus looking for a match in for the second row of Sheet1 while sRow is reset to 0 so it starts from the first row of Sheet2 so as not to miss any rows. What is wrong here?
    Last edited by excelforum123; 10-21-2010 at 10:09 AM. Reason: See my last post ITT

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,161

    Re: Macro goes into an infinite loop

    It didn't go into an infinite loop for me. I displayed "AAAA", "BBBB", "CCCC", "DDDD" and finished.

    I stepped through with F8 and then just let it run (F5).

    Not sure what it's trying to achieve but it doesn't loop (more than it should)

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,161

    Re: Macro goes into an infinite loop

    What is interesting is, if you change the first search string from 1111 to 1112 so that it doesn't match, it never goes through the part of the code which increments dRow.

    The implication is that it isn't finding what it is looking for.

    You could try setting the fourth parameter in INSTR

    Regards

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro goes into an infinite loop

    Please Login or Register  to view this content.
    Last edited by snb; 10-14-2010 at 01:15 PM.



  5. #5
    Forum Contributor
    Join Date
    06-28-2010
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Macro goes into an infinite loop

    Thanks. I don't know why it was infinitely looping for me. The same script started working properly without any changes. Weird.

    Also, thank you, snb. Novel suggestion, one I should remember but not for this particular example, as the actual has about 200 such entries going through the same procedure.

+ 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