+ Reply to Thread
Results 1 to 15 of 15

looking for a way to increase macro performance

  1. #1
    Forum Contributor
    Join Date
    09-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    127

    looking for a way to increase macro performance

    Currently this portion of my code takes about 15-20 minutes to run. I was wondering if any one had any suggestions on how to increase the speed of this code. Screen updating and display updates would already be set to false and calculations are set to manual. just would like to know if there is a way to replace the IF Else commands with something that will accomplish the same results quicker.

    thanks, s4

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: looking for a way to increase macro performance

    Do columns C and N have a different no of rows?

    If they don't you can probably combine the loops which should cut the time down a bit.
    Please Login or Register  to view this content.
    As well as that you can turn off screen updating, events and automatic calculation.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    09-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    127

    Re: looking for a way to increase macro performance

    that sounds like a good place to start. however i am struggling combining the two loops. the first loop fills in missing data on the original/source tab. the second loop moves the data based on certian criteria from the source tab to a new tab. when I try to combine them it skips the second loop entirely. do you know of a way to to this without using IF Else?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: looking for a way to increase macro performance

    Without using what If Else?

    I would have thought removing this,
    Please Login or Register  to view this content.
    changing Next sdn to sdnfix and adding Set sdn = sdnfix.Offset(,11) would have worked.

    It might have needed further tweaks but I don't see how an entire section of code would be skipped.

    Mind you all I can go on is the code, so perhaps there's something happening (not happening) that I don't know about.

    Any chance of some sample data?

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  5. #5
    Forum Contributor
    Join Date
    09-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    127

    Re: looking for a way to increase macro performance

    yes, I was wondering if there was another command that could replace the If Then Else. I don't have a sample file available due to confidential content. where I'm struggling on combing the loops is I need to look at each row and verify that all the data is present in the original table. if it's not then I would have to perform the "original first" loop, then while on the same row check the criteria to determine what part of the "original second" loop to execute. so in some cases this code needs to execute

    Please Login or Register  to view this content.
    then execute one of these 3 block Ifs
    Please Login or Register  to view this content.
    I'm not sure how to code it so it know when to do both (if needed) or to skip the "first" step and simply execute the proper block if in the "second" step.

    But I agree if there is a way to combine the two loops it should save significant time.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645
    You seem to have lost, or moved, the End If for the first If.

    That's the one from the first loop.

    If you have moved it that could explain why a large section of the code is, apparently, being skipped.

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: looking for a way to increase macro performance

    This is not tested, but perhaps it would give you ideas if it doesn't work(likely).

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    09-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    127

    Re: looking for a way to increase macro performance

    AlphaFrog -
    thanks for the different approach, However even when I modified to get it to work properly it still takes the about the same amount of time to execute. I do like the fact that the code itself is more condensed.

    Norie/AlphaFrog-
    I appreciate your interests in my post but I have been unable to make the improvements I was hoping to. I am going to keep searching around for another solution. When and if I find a quicker way I will post the changes I made.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: looking for a way to increase macro performance

    Did you try the other suggestions I made?

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: looking for a way to increase macro performance

    have you timed the sections of the code to see where the most time is actually taken?
    it's not efficient to do two vlookups of the same data for instance-you can use match to find the position and then refer to that row directly
    Please Login or Register  to view this content.
    rather than
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  11. #11
    Forum Contributor
    Join Date
    09-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    127

    Re: looking for a way to increase macro performance

    yes, thanks. I haven't been able to solve how to combine the first loop effectively with each of the 3 scenarios of the 2nd. Still playing with it, I feel it will save the most time since I would only be looping thru each row once instead of twice.

  12. #12
    Forum Contributor
    Join Date
    09-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    127

    Re: looking for a way to increase macro performance

    What I originally posted is one of 5 sections that I created individually then combined into one macro. That section of the code takes close to 20 minutes to execute with the data I have. thanks for the vlookup tip I will give that a go in a moment.

  13. #13
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: looking for a way to increase macro performance

    I reckon you'd probably need to post your workbook(s) to get big improvements-it's probably more a process issue than a code one

  14. #14
    Forum Contributor
    Join Date
    09-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    127

    Re: looking for a way to increase macro performance

    probably, but I was just looking for some quick suggestions. Combining the vlookup didn't save me much time with this file due to the fact there was less than a handful of cases where it was needed. But I have some other applications where it will come in more handy. thanks again.

  15. #15
    Forum Contributor
    Join Date
    09-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    127

    Re: looking for a way to increase macro performance

    I figured out a way to decrease the time it takes to execute dramatically. In it's orignal state it took around 25-30 minutes to run, now it takes less than 3 minutes. I was able to successfully merge some of the steps in my original code and elminate the need of using some lookup functions on a chunk of the data. The part that I merged followed directly below the code I originally posted and look like this,
    Please Login or Register  to view this content.
    After merging it with the section from my original post it now looks like this,
    Please Login or Register  to view this content.
    Doing that I was now only looping through each row once and using fewer time consuming functions. Thanks for pointing that out Norie.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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