+ Reply to Thread
Results 1 to 16 of 16

Macro running very slow

  1. #1
    Registered User
    Join Date
    12-21-2010
    Location
    Vancouver
    MS-Off Ver
    Excel 2007
    Posts
    83

    Macro running very slow

    Hi all,

    My code works great so i shouldn't really complain, but it is a little slow for a short macro(30 seconds). The code has been compiled using macro recorder and help from excel forum users (Thanks all!). I was just wondering if there were any ways to speed it up.

    Thanks for any help

    Tom

    Please Login or Register  to view this content.
    Last edited by oo0tommyk0oo; 06-21-2011 at 03:35 PM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Macro running very slow

    Hi
    Select and then using Selection takes longer than the below. Change the equivalant lines to the below and see how much time you save.
    Please Login or Register  to view this content.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  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: Macro running very slow

    All those Selections aren't necessary & will slow the code. Page setting in code can be slow
    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: Macro running very slow

    I don't know if everything you have is necessary in your code but I removed all of the .Select statements out:
    Please Login or Register  to view this content.
    .Select is always shown in a recorded macro but is not usually necessary when writing code.

    Regards
    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
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Macro running very slow

    I just lost the game! Wow MarvinP, I bow in your presence!

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Macro running very slow

    Hey Mordred,
    You beat me to the punch most of the time. I got you by 10 minutes on this one.

  7. #7
    Registered User
    Join Date
    12-21-2010
    Location
    Vancouver
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Macro running very slow

    Thanks to everyone for the quick response will give the code a try now.

  8. #8
    Registered User
    Join Date
    12-21-2010
    Location
    Vancouver
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Macro running very slow

    Works like a charm, takes about 10 seconds now. I'm guessing that is a normal time for changing all those column widths and borders.

    Thanks for all the Help!

  9. #9
    Registered User
    Join Date
    12-21-2010
    Location
    Vancouver
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Macro running very slow

    Quick update, i missed some of the updated code from Mordred, when i combined it with the code from MarvinP, it now runs in 3 seconds!

    Cheers!

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

    Re: Macro running very slow

    If you use an empty preformatted sheet, you can use it to format other sheets:

    Please Login or Register  to view this content.



  11. #11
    Registered User
    Join Date
    12-21-2010
    Location
    Vancouver
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Macro running very slow

    I didn't think of that.. the sheet i am copying from is identical in formatting, I'm simply removing all the formulas to values, so my coworkers can play with it without deleting anything important (they complain when i lock things as they like to edit everything)

    That would shorten the code to much though that when i showed my boss, she would not be so impressed!

    Will remember that for the future though!

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

    Re: Macro running very slow

    Quote Originally Posted by oo0tommyk0oo View Post
    That would shorten the code to much though that when i showed my boss, she would not be so impressed!
    Hahahaha. Does your boss actually want to see your code? I know that my boss's eyes glaze over when I have showed her code. LoL.

  13. #13
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Macro running very slow

    Do you need to set each one of those properties in .PageSetup? I know the recorder places them there, but most of the time, you only need the properties you are actually changing. If the default is fine, you don't need to include them.

    I am talking about all of this:
    Please Login or Register  to view this content.
    If all of that is set beforehand and is not changing, then you can omit all of that.

    It won't make your code all that much faster, but it will make it easier to read and edit.

  14. #14
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Macro running very slow

    Quote Originally Posted by oo0tommyk0oo View Post
    I didn't think of that.. the sheet i am copying from is identical in formatting, I'm simply removing all the formulas to values, so my coworkers can play with it without deleting anything important (they complain when i lock things as they like to edit everything)
    Why not do something like:

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    12-21-2010
    Location
    Vancouver
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Macro running very slow

    @ Mordred - No she glazes over as well, but i think it is important to show her every so often, so she knows how long it takes to keep changing it....

    @ Whizbang - That codes works great, and as the original source (with formulas) has a macro attached to it which resets all the page settings to how i want them, there is not need to do the same with the Version copy.

    Thanks everyone for the help

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

    Re: Macro running very slow

    @Whizbang

    In that case I'd prefer:

    Please Login or Register  to view this content.

+ 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