+ Reply to Thread
Results 1 to 13 of 13

Need to optimize code for faster processing

  1. #1
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Need to optimize code for faster processing

    Hello all. I think I finally have completed the project I have been working on but since it contains code from myself as well as several other folks from the Forum, it could use an expert to optimize it so it processes faster. I added a popup that displays the total processing time of the main code block and it currently runs on the attached file in .4ish seconds. The problem is running this on my production data currently creates 544 individual sheets and each sheet is processed before adding the next sheet, so the current processing time is almost 19 minutes on a decent workstation with 4GB RAM. The sorting of the sheets and the links on the 2_Summary sheet probably don't take too long but if they can be optimized that would be great too. Thanks in advance.

    Andrew

    EDIT - I added the timer to the sorting code and it takes almost 23 minutes to sort, so that needs optimization too!
    Attached Files Attached Files
    Last edited by drewship; 01-19-2016 at 01:54 PM.

  2. #2
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Need to optimize code for faster processing

    http://www.cpearson.com/excel/optimize.htm
    <---If my answer helped, please click *

  3. #3
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Need to optimize code for faster processing

    Thanks joe31623. I will take a look and see how much of that I can use.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need to optimize code for faster processing

    Another point you may consider is to avoid selecting object in order to take action on them. For instance in your procedure "CreateNewSheet".

    This section:

    Please Login or Register  to view this content.
    Can be rewritten like this:

    Please Login or Register  to view this content.
    Reference:

    http://dailydoseofexcel.com/archives...-and-activate/

    https://blogs.office.com/2009/03/12/...est-practices/
    Last edited by JOHN H. DAVIS; 01-19-2016 at 02:40 PM.

  5. #5
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Need to optimize code for faster processing

    Thanks John! I could get
    Please Login or Register  to view this content.
    to work as
    Please Login or Register  to view this content.
    but could not figure out how to combine it further.

  6. #6
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Need to optimize code for faster processing

    Please Login or Register  to view this content.
    gives me a "Copy method of Range class failed" error. Guessing it has to do with this section of code copying formulas, so I can't combine it?

    EDIT -
    Please Login or Register  to view this content.
    gives me "Object doesn't support this property or method"...probably because it is using an offset to reference a cell.
    Last edited by drewship; 01-19-2016 at 03:09 PM.

  7. #7
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Need to optimize code for faster processing

    Significant improvements just by adding
    Please Login or Register  to view this content.
    to a couple places in the code block that creates the sheets (14 minutes) and even bigger improvement using it in the sorting section (4 seconds)!!! Still working my way through the document but thanks again Joe!!!

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need to optimize code for faster processing

    For the first one (doesn't work with Paste Special):

    Please Login or Register  to view this content.
    For the second one, maybe:

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Need to optimize code for faster processing

    Thanks John. Did some testing yesterday without condensing the 2 above (which I started fixing today) and it seemed to actually take longer on my production file. Going to try running it a few times and changing things around to see what combination works the best.

  10. #10
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Need to optimize code for faster processing

    Please Login or Register  to view this content.
    is consistently slower than
    Please Login or Register  to view this content.
    although that seems counter intuitive. Just turning off calculations is faster than also changing this code.

  11. #11
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need to optimize code for faster processing

    Quote Originally Posted by drewship View Post
    Please Login or Register  to view this content.
    is consistently slower than
    Please Login or Register  to view this content.
    although that seems counter intuitive. Just turning off calculations is faster than also changing this code.
    This way is probably faster for that piece of code. Of course my suggestions are not meant to ignore Turning of Calculations, and ScreenUpdating, but in addition too.

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Need to optimize code for faster processing

    Thanks John. I will tinker with what you have provided and the other suggestions. The last one still increases the processing time and additionally, it messes up something in the code so the Conditional Formatting on 2_Summary column A does not show the colors.

  13. #13
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Need to optimize code for faster processing

    Just adding the updated file as it is working correctly and as fast as I have been able to make it. Try to condense some of the code as has been suggested above and see if your results are different than mine.

+ 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. Optimize a code
    By pezalmendra in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-06-2015, 05:31 PM
  2. Optimize code
    By DarkKnightLupo in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 02-19-2014, 08:58 AM
  3. optimize the Code needs to run faster
    By farrukh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-24-2012, 10:40 AM
  4. Optimize code
    By miso.dca in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-08-2011, 03:35 PM
  5. Streamlining VBA code to help faster processing
    By amid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-17-2009, 05:51 AM
  6. Can anyone optimize the code? (to make it work faster)
    By olegai in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-23-2007, 07:50 AM
  7. Optimize VBA code
    By doodlebug in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2007, 07:53 AM

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