Adding a If criteria within a Do Loop

  • Hi,


    I have a code that is working fine.


    The code searches a sheet 'License PWC' for the word 'Renewal'. If the word is found, it copies the entire row of data to another sheet 'expiry due 60d'. The rows of data are populated to column 12.


    Now, I would like to add in another feature. Column 13 is populated with "yes" and "no". If the word "renewal" is found, and if column 13 of that row is "no", only then it will transfer the data into sheet 'expiry due 60d'.


    My code is as shown:




    The code above works fine, without the added feature.
    I have tried to add in that feature with a IF command (commented out in the above code). If I uncomment the If command, the code runs into an infinite loop.


    Upon debugging, the following line is highlighted in yellow.


    Code
    expiredrow = foundcell.Row


    How should I include that feature into my exisiting code?


    Many thanks!

  • Re: Adding a If criteria within a Do Loop


    It looks like you have wrapped your additional 'if' statement around your 'if ... exit do' statement. Therefore if there is a cell which does not meet the "No" condition, your sub won't be able to test the 'firstadd' condition and will go into the infinite loop. So you need to move the end of the additional 'if' statement so it does not cover the 'if ... exit do' statement.
    Why not use 'autofilter' instead of doing this loops? I think this would be easier than the method you are using. Also, please provide sample data so that it is easier to advise.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!