+ Reply to Thread
Results 1 to 11 of 11

Very long macro - Thanks

  1. #1
    Registered User
    Join Date
    07-20-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    63

    Unhappy Very long macro - Thanks

    Hi All

    I used excel for year but only to do the simple things. I'm now getting into macro's, i have this macro that works but it takes an age to run and the screen flickering does my head in.
    I have a sheet call Bene, which in col BO with have CAT , A,B,C,D,E,F,G or H. It will then move all the A to Bene Cat A.

    I have only put this one on as an example but i have the same thing for UK,IBE,FRA,FIN
    and all have 8 sheets to go with them. I have used the same code for all macros and i've even done a macro that does them all together using the same code.

    Can someone please help me in making my macro more efficent
    Please Login or Register  to view this content.
    Last edited by E3iron; 02-10-2010 at 10:12 AM.

  2. #2
    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: Very long macro

    Hi,

    You'd be better advised to upload the workbook and some notes as to exactly what sheets you are wanting to use and what you're trying to achieve as output.

    It certainly looks as though the code could be simplified immensely. It may not even be necessary to use a loop to progress through cells in turn, a filtering function may be more appropriate. However even if a loop is required cutting out all the .Select and .Activate instructions, which I suspect are not needed, will speed up the code as well as switching off screen updating with Application.ScreenUpdating = False and probably temporarily putting the sheet(s) into manual calculation mode.

    Regards
    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.

  3. #3
    Registered User
    Join Date
    09-09-2009
    Location
    Chatham, ON
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Very long macro

    I agree with Richard, when i first started out with macro's i had lots of
    Please Login or Register  to view this content.
    in my code and stuff very similar that would slow it down and go from screen to screen causing it to take longer to run

    simply switching the above code to something along the lines of

    Please Login or Register  to view this content.
    or even
    Please Login or Register  to view this content.
    can start to speed up your run time i found.

    playing with stuff like that can slowly start to speed up your run time.

    Richard had a few other ideas that i will also be trying!

  4. #4
    Registered User
    Join Date
    07-20-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Very long macro

    I have attached part of the spread sheet, in col BO the is cat description either cat A,B,C,D,E,F,G,H.

    I need group these in to there own sheet.
    Attached Files Attached Files

  5. #5
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,177

    Re: Very long macro

    The number one tip I learned form this forum:
    Dont use ".Select". Change all the ".Select" to ".Activate"

    As an example: from your macro in the first post
    Please Login or Register  to view this content.
    I tried running your macro but could not get past:
    Please Login or Register  to view this content.
    It generates an error on Excel 2k.
    Regards

    Rick
    Win10, Office 365

  6. #6
    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: Very long macro

    Hi,

    As I thought this could be simplified to a few lines of code using a filter rather than looping through cells.

    First name your data range on the BENE sheet with the name 'Data' defined as:
    Please Login or Register  to view this content.
    Now use the following macro.

    Please Login or Register  to view this content.
    HTH

  7. #7
    Registered User
    Join Date
    07-20-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Very long macro

    I've rename the data range on the Bene sheet data and i have created the macro but i'm getting the error 'Range' of object'_Global' failed

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Very long macro

    This the macro I would use, a slight tweak to Richard's:

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 02-09-2010 at 12:59 PM. Reason: Added comments
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  9. #9
    Registered User
    Join Date
    07-20-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Very long macro

    Thanks Jb that works a treat, could you put some text in the code explaining how it works. I would like to understand.

  10. #10
    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: Very long macro

    Hi,

    Or a 3rd approach where you don't need to name the range data and don't need to start with all the 8 CAT worksheets just the single BENE sheet. i.e. in a loop copy the BENE sheet each time and delete the non relevant rows for the other categories.

    Please Login or Register  to view this content.
    I'm intrigued though as to why you need to create separate sheets in the first place when you could just have a macro that filtered the BENE sheet in response to an input.

    Regards

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Very long macro

    Comments added above into original macro.

    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].


    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated. It is found across from the "time" in each of our posts.)

+ 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