+ Reply to Thread
Results 1 to 11 of 11

Long VBA Code - Improve Efficiency?

  1. #1
    Registered User
    Join Date
    08-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    39

    Long VBA Code - Improve Efficiency?

    I have a very slow, time consuming macro (takes approx 25 mins to run on i7 32GB), that throws up the lack of resource Excel error and I was hoping somebody with more knowledge on VBA had any tips to improve the code and make it more efficient?

    Part of the code below...

    Any help greatly appreciated



    Please Login or Register  to view this content.
    Last edited by Dgp2012; 07-18-2013 at 11:29 AM.

  2. #2
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Kolkata, India
    MS-Off Ver
    Excel 2003/2007
    Posts
    182

    Re: Long VBA Code - Improve Efficiency?

    Hi Dgp2012,

    Check if the Copy and Paste special values parts can be done on entire range of formula portion at one go.

    regards
    taps

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Long VBA Code - Improve Efficiency?

    Untested!
    Provided your paste is correct, try this code. Since it is untested, it might throw you an error. If you get an error, tell me which line.


    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Long VBA Code - Improve Efficiency?

    Sorry for the delayed response...

    Thank you for your suggestion, I have applied the code and works great, with a slight amendment.
    For example:
    Please Login or Register  to view this content.
    It has made it marginally quicker by 1-2 minutes which is great.

    I also came across the Application.DisplayAlerts function which is excellent as it skips the resource warning, but I still would like to improve the speed of this code...any ideas ?!

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

    Re: Long VBA Code - Improve Efficiency?

    I'd suggest you try restricting the vlookup formulas to not look at entire columns when looking for an exact match
    Josie

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

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

    Re: Long VBA Code - Improve Efficiency?

    For A-1 on 'Sales Data'.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  7. #7
    Registered User
    Join Date
    08-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Long VBA Code - Improve Efficiency?

    Quote Originally Posted by Norie View Post
    For A-1 on 'Sales Data'.
    Please Login or Register  to view this content.
    I have just applied this code - incredible ! Took approx. 3 minutes, not 30 !!!

    Can i ask, if i wanted to calculate columns in a specific order - could this be done? i.e. calculate column N before M as M is dependent on N? I can work around this if its not possible.

    Also, how would i apply this new code to the second part of my initial code on the "Fixed" sheet. The formula was too long for VBA so had to store it in a cell.

    Thank you so much for your help!

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Long VBA Code - Improve Efficiency?

    I'd suggest setting calculation to off whilst running the macro then calculating everything at the end?

  9. #9
    Registered User
    Join Date
    08-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Long VBA Code - Improve Efficiency?

    Quote Originally Posted by yudlugar View Post
    I'd suggest setting calculation to off whilst running the macro then calculating everything at the end?
    Thanks Yudlugar,

    I am trying this now to see which method is quicker, straight to values or leave the formula until the end. Doing it this way would also mean i wouldn't have to calculate columns in a specific order too!

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

    Re: Long VBA Code - Improve Efficiency?

    I don't think the dependency should matter.

    All the formulas will be calculated at the same time as they would if you just copied them down.

    What I posted can only be used for contiguous ranges, for example columns A:I.

    The rest of your code seems to be kind of jumping all over the place.

    Mind you there does seem to be a pattern in the code for 'Fixed'.

    If there is then you might be able to use a loop for that part.

    I'll have a closer look.

    I've kind of checked this, making sure the right columns/rows are being populated, but that's all.
    Please Login or Register  to view this content.

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

    Re: Long VBA Code - Improve Efficiency?

    Oh, forgot to add - if this is running slowly then it might not be the code, have a look at the formulas.

    As Joseph has already suggested try not using entire columns with things like VLOOKUP.

  12. #12
    Registered User
    Join Date
    08-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Long VBA Code - Improve Efficiency?

    Thank you so much for your help - this has REALLY helped me !!

    I am going through all my VLOOKUPS and SUMIFS etc., and limiting to the range if its fixed to further improve the file.

+ 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