+ Reply to Thread
Results 1 to 7 of 7

Suggestions for speeding up macro run time

  1. #1
    Registered User
    Join Date
    12-15-2014
    Location
    Spokane, WA
    MS-Off Ver
    Office Professional 2007
    Posts
    7

    Question Suggestions for speeding up macro run time

    Hi all,

    First off, I've been coming to this forum for a long time as a guest and it has helped me tremendously!

    Now I have something that I'm hoping the community can help me out with; I've created a macro to perform several functions on a spreadsheet with multiple pages. The script works as expected but takes a very long (10min+) time to run making it largely counterproductive. I'd like to see if there are any suggestions for lightening the script or possible redundancies that I'm not seeing that could be contributing to the long run times (keeping in mind that there can be over 30,000 ro. Here's the details of what it does:

    Add new column to sheet1 and insert the word Apple on each line where there is data
    Select all cells with data and copy them.
    Paste to sheet2 at a specific location
    Erase the new column on sheet1
    Add new column to sheet3 and insert the word Orange on each line where there is data
    Erase extra spaces in one of the columns (this was due to the way the data imports)
    Select all cells with data and copy them.
    Paste to sheet2 below the data pasted from sheet1
    Remove the extra spaces from one of the columns
    Sort the data by the info in one of the columns
    Copy a row of formulas in the adjacent cells to where the data was pasted on sheet2

    The script is:

    Please Login or Register  to view this content.
    Any help with this would be greatly appreciated!
    Last edited by niccio2; 12-19-2014 at 04:38 PM.

  2. #2
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Suggestions for speeding up macro run time

    Please Login or Register  to view this content.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Suggestions for speeding up macro run time

    Hi, and welcome to the forum. Unfortunately your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    @tim201110 please note
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    12-15-2014
    Location
    Spokane, WA
    MS-Off Ver
    Office Professional 2007
    Posts
    7

    Re: Suggestions for speeding up macro run time

    Thanks Tim,

    I'm not sure where to insert your code though, can you clarify?

    Sorry Richard, I've updated the orifginal post to reflect the code box.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Suggestions for speeding up macro run time

    Quote Originally Posted by niccio2 View Post
    Sorry Richard, I've updated the orifginal post to reflect the code box.
    ...Noted. And thanks for the quick response.

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Suggestions for speeding up macro run time

    Hi niccio2,

    Excellent suggestion Tim. To implement Tim's code:
    Please Login or Register  to view this content.
    Tim's suggestions are the most efficient ways of improving performance, but there are other small things that will also help. For example:

    Code like the following could use the Actual Last Row used, instead of an arbitrary number:
    Please Login or Register  to view this content.

    and use the Actual Last Row and remove the while loop that is not needed:
    Please Login or Register  to view this content.
    See the attached file while tests and times the above code for various incremental changes.

    Lewis

  7. #7
    Registered User
    Join Date
    12-15-2014
    Location
    Spokane, WA
    MS-Off Ver
    Office Professional 2007
    Posts
    7

    Re: Suggestions for speeding up macro run time

    Thanks LJMetzger and Tim, that sped things up a ton!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Speeding up my macro
    By jsuarez199 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-03-2013, 10:52 AM
  2. [SOLVED] Code running slowly any way of speeding up processing time
    By boomboomblock in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-02-2013, 09:09 AM
  3. [SOLVED] Help in speeding up my macro!
    By shiva_reshs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2013, 12:04 PM
  4. Speeding up a macro
    By Mister P in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 12-20-2010, 02:50 AM
  5. Run Time Error '438' Code Suggestions?
    By Andy2010 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2010, 07:31 AM

Tags for this Thread

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