+ Reply to Thread
Results 1 to 21 of 21

2003 code runs super slow in 2010

  1. #1
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003/2010
    Posts
    15

    Question 2003 code runs super slow in 2010

    Hi,
    I am trying to run a suite of Excel 2003 spreadsheet macros on Windows 7 with Office 2010; I have not converted them as they are run by several sites globally who may not upgrade to Office 2010 at the same time. Hence they run in compatibility mode which in general is fine.

    However, certain macros are veeeery slow and to the user it would look like the app has hung. In debug I have found that the macro takes 10 minutes plus whenever it hits any of the following code:

    Please Login or Register  to view this content.
    It goes slow on each of the three 'lines' so it seems that it is actually doing an auto calc each time!

    Is there some configuration I can do to prevent this? Setting auto calc to Manual didn't help and anyway I loose things, like data validation, when I save it in Excel 2010.

    I tried removing the lines but that caused a runtime subscript out of range error elsewhere!

  2. #2
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003/2010
    Posts
    15

    Question Re: 2003 code runs super slow in 2010

    Here is some code, attached, that may help...
    Attached Files Attached Files

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: 2003 code runs super slow in 2010

    All the selections will slow down the code.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: 2003 code runs super slow in 2010

    Just to add to Roy's comment, your code has been recorded so every step taken has been recorded in the macro. Because of this, there is no doubt a lot of code in there that doesn't need to be, along with all of the Select statements.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  5. #5
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003/2010
    Posts
    15

    Re: 2003 code runs super slow in 2010

    Hi,

    The selections are fine and run at normal speed. It is the code in my OP that goes slow.

    Thanks,
    Bob

    PS I'm pretty sure the guy who wrote this may have started creating it by recording a macro but then expanded it manually.

    All steps work fine in Excel 2003 but the code mentioned in my OP runs like a dog in Excel 2010.
    Last edited by emanresu65; 06-02-2011 at 10:31 AM.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: 2003 code runs super slow in 2010

    In which other forum did you post your question ?



  7. #7
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003/2010
    Posts
    15

    Re: 2003 code runs super slow in 2010

    Quote Originally Posted by snb View Post
    In which other forum did you post your question ?
    Thank you for your interest. Mr Excel and Microsoft Answers, but no luck as of yet.


    It will require either someone who has come across this before or with a super understanding of Excel 2007/2010 changes to answer this I suspect.

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: 2003 code runs super slow in 2010

    Post the links.

    Also, selecting will slow the code down. It's generally not necessary.

  9. #9
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003/2010
    Posts
    15

    Re: 2003 code runs super slow in 2010

    Not sure why the interest in other forums? I've got the best response here, but here you go:
    http://answers.microsoft.com/en-us/o...&page=1#footer

    http://www.mrexcel.com/forum/showthread.php?t=552931

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: 2003 code runs super slow in 2010

    Read the Forum Rules

    8. Don't cross-post without a link. Cross-posting is when you post the same question in other forums on the web. You'll find people are disinclined to respond to cross-posts because they may be wasting their time solving a problem that has been solved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post. Expect cross-posts without a link to be closed.

    Read this to understand why we ask you to do this

  11. #11
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003/2010
    Posts
    15

    Re: 2003 code runs super slow in 2010

    Quote Originally Posted by royUK View Post
    Also, selecting will slow the code down. It's generally not necessary.
    I'm sure the macros can be improved in lots of ways, as I didn't write them.

    However, my main concern at the moment is just to get this Generate Statement code working at a reasonable speed.

    I have stepped through in debug and it is not until I hit the lines mentioned that it goes ultra slow.

    Checking again yesterday, I noticed that when it hit ".Calculation = xlAutomatic" I saw Calculate appear on the bottom left of the spreadsheet (i.e. the line actually made it do a calculation). I don't think that happens in 2003 but I'll go and test that now.

    With the PrecisionAsDisplayed line, I didn't see Calculate appear but it did still take an age to return as if it was doing something with the whole workbook.

  12. #12
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003/2010
    Posts
    15

    Re: 2003 code runs super slow in 2010

    Quote Originally Posted by royUK View Post
    Read this to understand why we ask you to do this
    Read and understood. Must admit, I assumed it just meant don't cross-post on different forums on the same web-site ('cos I shouldn't skim read!)

    Best go and post links on the other sites now....
    Last edited by emanresu65; 06-03-2011 at 04:29 AM.

  13. #13
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: 2003 code runs super slow in 2010

    It seems you are only interested in a simple solution. Why don't you stick to excel 2003 ?

  14. #14
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003/2010
    Posts
    15

    Re: 2003 code runs super slow in 2010

    Company decision. Eventually everybody will be Windows 7/Office 2010.

    Guy who wrote this left a while back and it has now fallen in my lap.

    It probably is a simple reason why this works in 2003 but not 2010, but I haven't come across it yet. Just hoping that someone else has.....

  15. #15
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003/2010
    Posts
    15

    Re: 2003 code runs super slow in 2010

    Quote Originally Posted by emanresu65 View Post
    Checking again yesterday, I noticed that when it hit ".Calculation = xlAutomatic" I saw Calculate appear on the bottom left of the spreadsheet (i.e. the line actually made it do a calculation). I don't think that happens in 2003 but I'll go and test that now.
    Yes, doesn't happen in 2003. Calc is set to automatic but it doesn't force a calculation.

    Quote Originally Posted by snb View Post
    It seems you are only interested in a simple solution.
    Not quite sure where you got that impression from. If you have a convoluted, difficult solution I am still interested. Please let me know!
    All I have been doing is highlighting where the problem lies. What I'll do is see if I can make a cut down version and see if it has the same problem, then I can attach that instead.

    Thanks everyone for your help.

  16. #16
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: 2003 code runs super slow in 2010

    Please Login or Register  to view this content.
    This switches calculation to Automatic, if it's part of a loop it will be running multiple times. If you only need calculation to be automatic for part of the code, then you need to reset it to manual. There should be no difference how this works in Excel 2007.

    We need an example workbook to see what the problem is

  17. #17
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003/2010
    Posts
    15

    Re: 2003 code runs super slow in 2010

    I'm trying to find time to create a meaningful cut-down version which still shows the issue....I may be a few days!

    When I have one or have identified the issue then I will post back.

    Thank you.

  18. #18
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003/2010
    Posts
    15

    Re: 2003 code runs super slow in 2010

    A little more on this....

    Whilst still going slow on the "With Application .Calculation = xlManual .MaxChange = 0.001 End With" lines, I found that pressing on <F8> again would push on through the code. Btw, also I realise now that "Calculate" in the bottom left allows me to force an update if I click on it and doesn't mean it is actually doing a calculation. Doh!


    However, it then really gets stuck on subtotals and pressing <F8> just makes the VBA screen go an opaque white until it finishes whatever processing it is doing.

    For example
    Please Login or Register  to view this content.
    The named range contains a few lines of data and the remaining rows are empty. Every cell contains a formula, however, grabbing info from another sheet in the workbook. e.g. "=IF(Collateral!C4="","",UPPER(Collateral!C4))".

    It takes many minutes to process this which seems strange for only 50 rows.

    N.B. Code already has Application.ScreenUpdating = False and I have also added Application.DisplayStatusBar = False

  19. #19
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: 2003 code runs super slow in 2010

    The code you provided in the Word document is really bloated. With the line of code that you posted
    Please Login or Register  to view this content.
    the whole sheet and its cells are having this action performed on them, which will severely slow things down considering it will have to calculate 16,777,216 cells (for which it is quite likely you are not using them all). The code that the other guy made and left for you to work on looks like it was recorded, which is not the most efficient way to run code. Your code needs an overhaul but a mock workbook may be necessary to achieve this.

  20. #20
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003/2010
    Posts
    15

    Re: 2003 code runs super slow in 2010

    Hi Mordred,
    Does it do the calculation when the mode is set to xlAutomatic or when an update is next made to the workbook? I was expecting the latter but starting to suspect the former!

    However, I eventually reconfirmed my problem was on the subtotal command - at which point calculation has been set to xlManual. In the last example I posted it should only be looking at 2,500 cells.

    I now have Microsoft on the case. When I know the solution/reason why I'll post back, probably in a couple of weeks, and let you know.

    Meanwhile, I'll tell you I have just finished a first draft of a stand-alone version which is huge (having to contain the data rather than links to it) though some of the filtering is gone. Now the statement is created much faster, though it is still slower than when I run it in 2003; 2 to 4 secs in 2003 vs 12 to 15 secs in 2010.

  21. #21
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003/2010
    Posts
    15

    Re: 2003 code runs super slow in 2010

    Hi all,

    Apologies for not posting answer sooner ...


    Excel 2003 differs from 2007/2010 in that the later versions have a new smart calculation engine, so it works pretty much differently from before.

    The code written by the original author had several of those "Application.Calculation" commands.

    I discovered that with the new calculation engine I didn't need any of those commands!

    All I did in the end was to strip them all out and it worked like a dream.


    Kind regards,
    Bob

+ 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