Loop Gets Slower

  • Hi all,


    I have looked around the net, but cant seem to find a "reason" as to why a loop gets slower... The first 10,000 rows gets done in 3 secs, rows 80,000-90,000 takes 30 secs. Does anyone know why? I have screenupdating, displayalerts, enable events and calculation all set to false, my data is sorted as applicable, there are no objects on each loop, I use evaluate in vba, and as data is sorted any ranges are down to the minimum (basically I find the first and last row for a searched value) just cant seem to find why it slows down.


    I know there may be alternatives to loops, my question is why would the loop slow down in the first place (and the way this project is going I have to use loops as requirements keep changing)? The data set is 100k rows and it runs in around 8 mins to calculate approx. 20 columns of counts, match/index etc.... Mind you them doing it manually took them 6 hours last week so still better than it was!

  • Re: Loop Gets Slower


    What's inside the loop?

    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

  • Re: Loop Gets Slower


    Quote from rory;789048

    What's inside the loop?


    Nothing too horrific...



    frmPBIUpdate is a form, all the variables are declared as longs. Every 10,000 rows seems to add 4 seconds, but im not sure why. I have to use loop for now to "get it working" - the whole procedure takes about 8 mins (the data set is 900,000 rows to start with), so its no slouch, but I cant understand why the loop is slowing down.

  • Re: Loop Gets Slower


    Why do you keep showing the form again?


    I suspect your code would be a lot faster if you used arrays. (and a lot neater and easier to maintain with a couple of worksheet variables! ;))

    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

  • Re: Loop Gets Slower


    Hi Rory,


    The statusbar goes missing in excel 2016 and as im testing it through i just wanted to see what the code was up to, the userform can also go missing during run time hence the check. The person asking me for help, doesnt know what they want, doesnt really understand how it currently works, but wants me to solve it!


    I use loops and match simply as specs often change when others know what they want, and i can then update the bits and pieces... Anyway, on this i just wondered why the loop slowed down, as i cant see an obvious reason for it... Just seems abit odd that the first few rows goes relatively quick!

Participate now!

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