+ Reply to Thread
Results 1 to 19 of 19

VBA optimization

  1. #1
    Forum Contributor
    Join Date
    09-21-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    131

    VBA optimization

    Hello all,

    Could you please help me optimizing VBA?

    I got series of VBA scripts running every hour and I think it can be optimized as I have seen excel being not responded for over 12 minutes so I believe it just needs optimization. Please see code below:

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: VBA optimization

    Hi !

    This bad code (full of Select, Selection, awfull ! ) ends in tenth of a second !

    So if this code runs over 12 minutes, the truth is elsewhere

  3. #3
    Forum Contributor
    Join Date
    09-21-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    131

    Re: VBA optimization

    Quote Originally Posted by Marc L View Post
    Hi !

    This bad code (full of Select, Selection, awfull ! ) ends in tenth of a second !

    So if this code runs over 12 minutes, the truth is elsewhere
    No, this is only the part of a code that I'm asking you guys to optimize.

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

    Re: VBA optimization

    Please Login or Register  to view this content.

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,907

    Re: VBA optimization

    I'd do something like below.

    Please Login or Register  to view this content.
    OptimizeVBA is trick I learned at http://analystcave.com/

  6. #6
    Forum Contributor
    Join Date
    07-23-2016
    Location
    Texas
    MS-Off Ver
    2016
    Posts
    273

    Re: VBA optimization

    Try worksheets ("S11").rows("1:" & rows.count).clearcontents for each sheet.

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,483

    Re: VBA optimization

    The previous reply indicates, the code you provided would in no way run for 12 minutes, there must be some other code that is kicking in that is causing your code to run for a long time, possibly a wack of formulas could be causing the issue. Then set your calculate to manual.

    Anyway, you can get rid of your selects,

    Please Login or Register  to view this content.
    Can be modified to possibly
    Please Login or Register  to view this content.
    Last edited by davesexcel; 12-13-2016 at 02:12 PM.

  8. #8
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA optimization

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  9. #9
    Forum Contributor
    Join Date
    09-21-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    131

    Re: VBA optimization

    Quote Originally Posted by mehmetcik View Post
    Please Login or Register  to view this content.

    What if I would like to perform the same task but across sheets that are named differently. For example "AMPL" YEHK" "UIOS". Would it be possible to perform the task as efficiently as if a ran on sheets named S0*

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: VBA optimization


    Yes for example if their indexes are closed like worksheet #4 to #6 …

    Or like post #7 …

  11. #11
    Forum Contributor
    Join Date
    09-21-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    131

    Re: VBA optimization

    Quote Originally Posted by Marc L View Post

    Yes for example if their indexes are closed like worksheet #4 to #6 …

    Or like post #7 …
    Which option is quicker to run? My project is still in early stages so i'm able to change the structure of it.

  12. #12
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA optimization

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    09-21-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    131

    Re: VBA optimization

    Quote Originally Posted by mehmetcik View Post
    Please Login or Register  to view this content.
    Im trying to run this code below, but it doesnt seem to work. Compiler highlighting line 5.

    Please Login or Register  to view this content.
    Last edited by ChipsSlave; 12-13-2016 at 04:31 PM.

  14. #14
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,483

    Re: VBA optimization

    Your range has to be qualified as well
    Please Login or Register  to view this content.
    Look at my original code, that is why I used with and end with

  15. #15
    Forum Contributor
    Join Date
    09-21-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    131

    Re: VBA optimization

    Quote Originally Posted by davesexcel View Post
    Your range has to be qualified as well
    Please Login or Register  to view this content.
    Look at my original code, that is why I used with and end with
    I'm sorry but I don't follow. Could you please explain me this a bit more.

  16. #16
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA optimization

    Sorry, this version works.


    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    09-21-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    131

    Re: VBA optimization

    Quote Originally Posted by mehmetcik View Post
    Sorry, this version works.


    Please Login or Register  to view this content.
    I can confirm it works. Thank you for your support.

  18. #18
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,932

    Re: VBA optimization

    @ChipsSlave

    Don't quote whole posts -- it's just clutter. If you are responding to a post out of sequence, limit quoted content to a few relevant lines that makes clear to whom and what you are responding

    For normal conversational replies, try using the QUICK REPLY box below.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  19. #19
    Forum Contributor
    Join Date
    09-21-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    131

    Re: VBA optimization

    Quote Originally Posted by mehmetcik View Post
    Sorry, this version works.
    I'm sorry for bugging you, but could you show me how do I optimize this code?

    It should filter table COMP_summ_9 by DTTD, FDTL,... and then select A2:C2 ctrl+shift down and copy selection to the DTTD,FDTL,... sheets and paste it into A3 cell. I was able to optimize other bits of the code just this one seems a little bit to difficult to me as I am not an expert of VBA. Thank you.

    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)

Similar Threads

  1. [SOLVED] sumproduct optimization
    By miller_ilya in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-18-2013, 09:23 AM
  2. Warehouse Optimization
    By Matt Lee in forum Excel General
    Replies: 8
    Last Post: 12-29-2010, 05:14 PM
  3. Optimization with solver
    By Homeboy_8 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-15-2010, 03:15 AM
  4. cutlength optimization
    By EMAN in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-08-2010, 11:59 PM
  5. Optimization Question
    By Multistrada in forum Excel General
    Replies: 3
    Last Post: 11-08-2010, 12:10 PM
  6. Code optimization
    By d_omin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-27-2010, 04:13 AM
  7. I need of optimization -Please help!
    By Mm73 in forum Excel General
    Replies: 1
    Last Post: 08-25-2008, 02:18 PM
  8. optimization
    By kckar in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-09-2005, 01:05 PM

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