+ Reply to Thread
Results 1 to 7 of 7

Excel Macro needs to be optimized (speed up the execution)

  1. #1
    Registered User
    Join Date
    06-20-2015
    Location
    Chennai, India
    MS-Off Ver
    2010
    Posts
    59

    Excel Macro needs to be optimized (speed up the execution)

    Dear All,

    Please find attached a macro, which is doing the job correctly, but takes bit longer time to complete. This needs to be optimized to deliver the result swiftly.

    Step1: its finding the char present in col a in the word avaialble in col b, if that char is avl in the word then it will color that word in blue.
    Step2: Then, do the same for the list in column F but colour it green
    Step3: then find the % of characters which are neither green nor blue
    Detailed Step3:

    I have a list of sentences, some of the characters in the sentences are colored green (colorindex = 10), some are colored blue (colorindex = 5) and some are colored black. I would like to calculate the proportion of each sentence which is colored either blue or green.

    I have written a macro which loops through each character in each sentence and determines what color it is, then spits out the proportion of non-black colored characters in that sentence. The problem is that this is very slow, I believe there are more advanced techniques which can be used in VBA such as storing information in an array then spitting it out as an array at the end. I'm not too sure, if someone could may me make this faster it would be much appreciated!

    P.S.:

    You can see in the sub routine titled "Colouring" there is a bit of code which I have commented out called "perform the counts"
    This runs very quickly, but is slightly different from what I want. Hence someone pls help me to solve my problem.


    Thanks.
    Attached Files Attached Files

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel Macro needs to be optimized (speed up the execution)

    Hi Kevivu,

    It ran in 2.5 s after I got rid of the debug print in "key_in_phrase_helper" and the msgbox in "Colouring2"

    And I commented out all the:
    Application.ScreenUpdating,Application.DisplayStatusBar and Application.Calculation lines in the called routines.


    * an order of magnitude faster - your code is already optimal
    Last edited by xladept; 12-10-2015 at 08:42 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    06-20-2015
    Location
    Chennai, India
    MS-Off Ver
    2010
    Posts
    59

    Re: Excel Macro needs to be optimized (speed up the execution)

    Thanks a lot for the help...

    Is any other way to further optimize (improve the execution speed) this code...

    Thanks

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel Macro needs to be optimized (speed up the execution)

    Thanks for the rep! I'll take another look tomorrow - how many lines are you processing??
    Last edited by xladept; 12-13-2015 at 01:54 PM.

  5. #5
    Registered User
    Join Date
    06-20-2015
    Location
    Chennai, India
    MS-Off Ver
    2010
    Posts
    59

    Re: Excel Macro needs to be optimized (speed up the execution)

    Mate, we used to process millions of lines... Thanks in advance...

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel Macro needs to be optimized (speed up the execution)

    I got it down to 2.37s -see the red code - but since you're handling the font color, an array won't work!

    I don't think you can do much better


    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-20-2015
    Location
    Chennai, India
    MS-Off Ver
    2010
    Posts
    59

    Re: Excel Macro needs to be optimized (speed up the execution)

    thanks a lot mate.. for your help...

+ 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. execution speed comparrision
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-27-2015, 01:40 PM
  2. Speed up this macros execution
    By banaanas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-01-2015, 01:58 AM
  3. Want to Speed Up Code Execution
    By PosseJohn in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-28-2013, 07:34 PM
  4. Execution speed of macros
    By JM967 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2013, 02:43 PM
  5. [SOLVED] Execution Speed of VBA Code
    By sdelaney7 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-17-2012, 08:35 PM
  6. how to speed up macro code execution?
    By sharmanjali87 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-03-2010, 06:45 AM
  7. Speed up Excel execution
    By Sinus Log in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-08-2005, 01:10 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