+ Reply to Thread
Results 1 to 7 of 7

How to speed up loop code

  1. #1
    Registered User
    Join Date
    08-11-2013
    Location
    leeds
    MS-Off Ver
    Excel 2007
    Posts
    30

    How to speed up loop code

    I have a userform, the main function is to read a list of reference numbers, find the matching record/row on our excel database and mark an offset cell with a temporary value.

    It works as it should but I am now trying to speed it up and im thinking the majority would need re-writing. I hae tried implementing the following code to speed things up
    Please Login or Register  to view this content.
    This didn't help at-all. The speed is the same, but now the excel window disappear randomly while the code runs



    Here is the userform code
    Please Login or Register  to view this content.

    My code might give away I am something of a novice. Regardless this is an app I need to create.
    Is it the me.repaint that slows things down? or the method used for looping? (finding the last row then looping 1 to, its the only way i currently understand).

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to speed up loop code

    Probably because you're repainting with each iteration - why don't you repaint afterwards??
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    08-11-2013
    Location
    leeds
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: How to speed up loop code

    I was using this to show progress. Is there an easy to implement alternative? Ive never liked the progressbar because Ive never managed to make it scale correctly.

  4. #4
    Registered User
    Join Date
    08-11-2013
    Location
    leeds
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: How to speed up loop code

    update: I have removed the me.repaint to no avail. The code takes just as long. Thanks for the suggestion. Do the loops need doing a different way?

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to speed up loop code

    Maybe:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    08-11-2013
    Location
    leeds
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: How to speed up loop code

    Quote Originally Posted by xladept View Post
    Maybe:

    Please Login or Register  to view this content.
    I got a little too clever for a day, and dismissed your answer! Im very sorry because I tried it today, by setting the textbox's value as a variable and then using that variable in the loop. Thank you

    My question is, for my own understanding of excel; Why does that slow the loop? I notice you highlighted the .enabled = false statement, but the value was always read!

    Once again thank you, rep+1

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to speed up loop code

    I think, but I don't know, that having the textbox disabled confused the VBE and so it took a lot longer - and you're welcome!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Speed up Macro Loop
    By jbench18 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-31-2013, 01:15 PM
  2. [SOLVED] Speed Up Loop in VBA
    By PY_ in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-19-2013, 08:57 AM
  3. [SOLVED] Help Speed up this Loop?!?
    By arleutwyler in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-06-2013, 01:49 AM
  4. Speed up a VLookUp loop
    By wizuriel in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-11-2013, 07:28 PM
  5. Speed Up VBA Loop Code
    By rlsublime in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 12-30-2012, 07:20 PM

Tags for this Thread

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