+ Reply to Thread
Results 1 to 7 of 7

Macro simplification & efficiency

  1. #1
    Registered User
    Join Date
    10-26-2011
    Location
    Leicester, England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Macro simplification & efficiency

    Hi All,

    Hopefully one of you will be able to help me. I've just written a Macro to export information from a source sheet into two other sheets: one to have a simple mail merge run on in, and the other to prepare a spreadsheet for copying to a CSV sheet manually.

    The code now works perfectly, albeit incredibly slowly. I'm pretty sure that this is largely due to the fact that my code is continually jumping between sheets, but because of the functionality I require (or at least in the way that I have gone about achieving it) I couldn't find a way around it.

    I'm fairly new to Macros, this being only my 2nd, so it basically just replicates what I would do it I was doing it manually. It is based primarily around 2 loops. The first loop checks each cell in a column one by one for the word "YES", at which point it exports selected data to another sheet. The loop repeats until the end of the column (using if Blank) and then moves on to the next column, at which point the loop is triggered again and run on that column, a process which runs until the macro encounters a blank column.

    I'd just like to know if anyone can see anything in my code that could be achieved in a more efficient way? It took about 20 minutes to complete a test run with only 3 columns to be checked; the full version will have up to 20 colums!

    Please Login or Register  to view this content.
    Thanks in advance, Joe
    Last edited by shapesphere; 10-26-2011 at 05:04 AM. Reason: Didn't close the CODE tag properly

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

    Re: Macro simplification & efficiency

    Don't select, it's rarely necessary

    Edit: Check what the code is doing, these first 4 lines aren't necessary
    Please Login or Register  to view this content.
    Last edited by royUK; 10-26-2011 at 05:19 AM.
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    10-26-2011
    Location
    Leicester, England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Macro simplification & efficiency

    Thanks royUK, I have tried to avoid it where I can but for (most of) the places I've used it I couldn't see a way around it

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

    Re: Macro simplification & efficiency

    Here for instance

    Please Login or Register  to view this content.

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

    Re: Macro simplification & efficiency

    To further explain:

    This
    Please Login or Register  to view this content.
    Can be replaced with this
    Please Login or Register  to view this content.

    and this
    Please Login or Register  to view this content.
    can be replaced by this
    Please Login or Register  to view this content.
    Here are some useful links:
    http://www.dailydoseofexcel.com/arch...-and-activate/
    http://www.nimblecoder.com/blog/arch...beginners.aspx
    http://www.excelforum.com/excel-prog...id-in-vba.html

  6. #6
    Registered User
    Join Date
    10-26-2011
    Location
    Leicester, England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Macro simplification & efficiency

    Thanks for the help guys, I can cut out a lot of the page switching now but because a lot of my formula is based on relative cells it still takes an age to do anything. I think I'm just going to have to deal with it being slow, or try and re-write it :/

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

    Re: Macro simplification & efficiency

    If you would be willing to post your cleaned up code (i.e. minus as much of the .select statements as you are able) then I am sure that someone will be willing to help improve the speed of the code.

    For instance, adding this to your code will improve speed:
    Please Login or Register  to view this content.
    This link will explain this and other techniques to use to speed up code.
    http://blogs.office.com/b/microsoft-...practices.aspx
    Last edited by Whizbang; 10-26-2011 at 04:14 PM.

+ 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