+ Reply to Thread
Results 1 to 10 of 10

Slow running macro

  1. #1
    Registered User
    Join Date
    11-29-2005
    Posts
    12

    Slow running macro

    Hello All,

    Below is the entire code that I am using. It is a simple routine which checks whether a part has started its release process or not, based upon dates. The code works and does what I want.

    The problem that I have is that it is very slow, for example it takes 35 seconds to go through 530 lines items. In my (limeted) experiance, based on other VBA doodlings this slow.

    I would appreciate some guidance as to how to improve the efficiency and speed of this.

    Please Login or Register  to view this content.
    Thank you for your help.

  2. #2
    Forum Contributor
    Join Date
    01-10-2006
    Location
    Ahmedabad, India
    MS-Off Ver
    Office 2000
    Posts
    346
    Yes it does appear to be simple routine. Is your column A cells really empty after 530 lines of data? May be it is looping for a much longer count. Why not add msgbox i as last line to find out what is the last count? It should be 530 or nearby as per data volume you mentioned.

    A V Veerkar

  3. #3
    Forum Contributor
    Join Date
    03-24-2004
    Location
    Edam Netherlands
    Posts
    181
    Is this faster....?

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    Nice one Kaak,

    I didn't consider removing all the range variables but it's probably fair enough considering that they are only referred to once/twice.

    Pjjclark, another variation which I made before I saw Kaak's version is below & uses a select case layout rather than If clauses & tries to remove any repetion from w/in the cases. I've put in the "set... = nothing" to try & prevent "stack overflow" which I've never experienced but have read about.

    change the order of the Select Case options so that the most likely one is listed first. If this means reversing a case "" with a case else, then you could change the code to read case <> "" and case else.

    Please Login or Register  to view this content.

    Another option would be to use the above select cases/If layout with Kaak's suggestion of "range(..." or to use the "cells(i,..." as needed.

    Let us know how it goes - I'm interested to see which approach is the fastest.

    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  5. #5
    Registered User
    Join Date
    11-29-2005
    Posts
    12
    Right then, after much scientific testing conditions, I can now divulge the results.

    Kaak time of 30s
    broro183 time of 40s
    mine time of 41s

    I have checked the number of line items that it runs through and its 554, and this applies to all.

    The spreadsheet is a 2mb file with 6 worksheets, I have removed the 5 sheets that I don't need and re-saved: there is no difference.

    I have re-booted my machine (as excel crashed just before home time yesterday): no difference.

    My feeling that this is more of a computer issue then a VBA issue.

    Any other thoughts before I start dismantaling?!

  6. #6
    Registered User
    Join Date
    11-29-2005
    Posts
    12
    btw, thank you for your contributions.

  7. #7
    Forum Expert
    Join Date
    09-09-2005
    Location
    England
    MS-Off Ver
    2007
    Posts
    1,500
    The obvious other things to try are turning off the calculation and screenupdating at the top of the macro and turning it back on at the end, are there other formulas on the worksheet that may be recalculating every time you update the sheet?

    Please Login or Register  to view this content.

    any quicker?

    Regards

    Dav
    Last edited by VBA Noob; 10-03-2007 at 11:02 AM.

  8. #8
    Registered User
    Join Date
    11-29-2005
    Posts
    12
    Wow, quite a difference. We're down to 1s. I'll be using that in everything I do!

    Thanks for the top tip, Dav. Cheers

  9. #9
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    ahhhh, of course...
    Duh me, why didn't I think of suggesting that?
    note to self - take my blinkers off!
    (I usually throw the screen updating one in but forgot this time & I never even thought of the calc' mode.)

    You may have to be cautious using the "Application.Calculation = xlCalculationManual" in some of your other macros ie if the macro uses calculated values which are collected from the spreadsheet during runtime it may pick up an incorrect value.

    Rob
    Last edited by broro183; 10-04-2007 at 05:02 AM.

  10. #10
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    This link is a good read. Gives various tips including clear some old junk off the PC to speed it up

    http://www.decisionmodels.com/optspeedd.htm

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

+ 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