+ Reply to Thread
Results 1 to 9 of 9

Slow running code

  1. #1
    Forum Contributor
    Join Date
    06-05-2006
    Posts
    166

    Slow running code

    Hi,

    I have pretty basic skills so wondered if anyone could help me please. I have written/recorded the following macro:

    Please Login or Register  to view this content.
    Although this works fine for it's intended purpose it is very slow to run (I am looping this macro thousands of times). I have tried cleaning up areas of it where I could but wondered if there was a way of coding this that would help it to run quicker.

    Many thanks in advance for any help!

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Slow running code

    You may avoid selecting and if you must run the code in a loop there is no need to reset the sort fields within the loop - only apply the sort.

  3. #3
    Registered User
    Join Date
    11-21-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Slow running code

    Phil2006,

    Try switching the calculations to manual at the start of your code - then to automatic again at the end.
    It will hang for a while at the end, but it will be much more efficient than recalculating after every change.

    'Application.Calculation = xlCalculationManual

    Application.Calculation = xlCalculationAutomatic'

  4. #4
    Forum Contributor
    Join Date
    06-05-2006
    Posts
    166

    Re: Slow running code

    Hi guys,

    Thanks so much for a quick response! Sorry to be a bit basic but how do I avoid selecting if I need to use the data in the cells I had been using the select function for?

    Kurt - Thanks! I have that done in the looping macro; the code looks like this:

    Please Login or Register  to view this content.
    Thanks again so much for helping

  5. #5
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Slow running code

    For example:
    Please Login or Register  to view this content.
    can be:
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    06-05-2006
    Posts
    166

    Re: Slow running code

    Thanks again Izandol! I have now removed all the Select functions as you suggested and it is improved. It is still taking a long time though, any more tips would be most appreciated - I do think that this can run quicker as I had a similar function previously that did the same job but was much quicker!

    Thanks again for all your help so far, it is very appreciated!

  7. #7
    Registered User
    Join Date
    11-21-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Slow running code

    Phil2006

    Do you have any vlookup formulas, graphs etc on any of your worksheets? or are other worksheets sharing the data you are sorting?

  8. #8
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Slow running code

    It is difficult with only part of the code but you may try:
    Please Login or Register  to view this content.
    and:
    Please Login or Register  to view this content.
    I do not know if there is more code for Paste_Macro.

  9. #9
    Forum Contributor
    Join Date
    06-05-2006
    Posts
    166

    Re: Slow running code

    Thanks, I will try that now. My above post contains the full code for the macro. Some of the sheets do have a lot of formulae on (no vlookup) but holding the calculate button doesn't cause any problems and all formulae update really quickly so I wouldn't have thought that would be a problem.

    Thanks again

+ 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. vba code running too slow
    By hitsujicute in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-31-2013, 06:00 PM
  2. VBA Code running very slow. Need help
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-21-2013, 02:13 PM
  3. Macro code is running to slow
    By chsaav in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-23-2011, 05:00 AM
  4. Slow running code
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-06-2008, 12:49 PM
  5. Code running slow
    By lou031205 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-08-2007, 12:20 PM

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