Looping code never ends

  • Hi All!


    I am using this replace code to reset some formulas in my workbook. The problem is it replaces "=" with "=" (by design, I want it this way) and thus it goes on forever till I stop it with ESC.

    Is there a way to adapt it to go through all the sheets in the workbook once and be done?


    Thanks!


  • What you describe is exactly what your code does. It does not loop infinitely, it's probably just very slow.


    Why exactly do you need to do this?

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • This may sound like a silly question, but why find something and then replace it with the same thing?

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • No, I understand that that is strange.

    I have other code running on this workbook and many cells turn to #Ref or VALUE. Replacing "=" with "=" in the whole workbook resets all the formulas and fixes everything. the code works it just doesn't ever stop because it goes back to the beginning and finds more"=".

  • What you describe is exactly what your code does. It does not loop infinitely, it's probably just very slow.


    Why exactly do you need to do this?

    See above for reasoning.

    It's definitely looping I can see it going through my first sheet multiple times about 2 minutes apart and i have left it on for 10 min.


    Anyway to have the code go through each sheet in the wb only once?

  • The only reasons I can think of that could cause it to do that are:


    1. Some event code is calling this routine again; or

    2. You have previously run a manual Find and/or Replace operation and specified to look in the whole workbook.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • I just made a minor change so that the replacement applies only to the used range and not all cells in each sheet. As far as I can see, the code should loop only once through each sheet. Can you attach a copy of your file (de-sensitized if necessary)?

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

Participate now!

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