+ Reply to Thread
Results 1 to 9 of 9

Formatting sheets with macro running very slowly

  1. #1
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Formatting sheets with macro running very slowly

    My code to format my sheets is below, but it runs very very slowly....any way I can make this more streamlined?

    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,644
    Getting rid of all the Select/Selection in the code might speed things up a bit.

    However, I think the main bottleneck is the two loops.

    Not sure what you can do about them.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    11-26-2012
    Location
    Kitchener, Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: Formatting sheets with macro running very slowly

    Hi nickmax1,
    Try to avoid interactive command like ".Select"
    for example instead of
    Please Login or Register  to view this content.
    use

    Please Login or Register  to view this content.
    Try this and if you still have problem let us know
    aelgadi

    > Click Star if I helped. Thanks

  4. #4
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Formatting sheets with macro running very slowly

    What I notice is that you first select a range and then apply the formatting to the range. This is often not really necessary as you can apply formatting also with physically selecting the cells. I have personally found the latter method to be quicker. I have re-written some of the code and on my PC it runs in less than a second

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Formatting sheets with macro running very slowly

    invalid use of property when i change . select to .font

    ??

  6. #6
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Formatting sheets with macro running very slowly

    Hi Nick,

    I have made all the changes needed in the code I posted above which runs without any errors

  7. #7
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,883

    Re: Formatting sheets with macro running very slowly

    The macrorecorder is not that smart. Apart from using Select all the time it also records all properties even though just one or two has been changed.
    Since you start by clearing the format on the whole range you can delete all the formatting commands that just sets the values to their defaults.

    The first bunch of lines looking like this:
    Please Login or Register  to view this content.
    could be changed into something like this:
    Please Login or Register  to view this content.
    Note also the dim x statement. That tells VBA that I'm gonna use a variable named x and that it will contain a range. This saves a little bit of memory and speeds things up just a little bit.
    I haven't tested this code and I may have deleted some rows that were not the defaults but hopefully it will give you some leads anyway.
    <----- If you were helped by my posts you can say "Thank you" by clicking the star symbol down to the left

    If the problem is solved, finish of the thread by clicking SOLVED under Thread Tools
    I don't wish to leave you with no answer, yet I sometimes miss posts. If you feel I forgot you, remind me with a PM or just bump the thread.

  8. #8
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Formatting sheets with macro running very slowly

    thanks Olaf,

    it seems to run a little quicker, about a minute on my machine. It was about 2 minutes before that.

  9. #9
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Formatting sheets with macro running very slowly

    thanks Jacc that shaves of a bit of time as well getting rid of the pointless macrorecorder code.

+ 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