+ Reply to Thread
Results 1 to 11 of 11

How can I optimize my code

  1. #1
    Registered User
    Join Date
    03-11-2019
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    8

    How can I optimize my code

    Period Backlog at the start of the month Volume Receive during the month Incident Completed during the month
    Apr-17
    May-17
    Jun-17
    Jul-17
    Aug-17
    Sep-17
    Oct-17
    Nov-17
    Dec-17
    Jan-18
    Feb-18
    Mar-18
    Apr-18
    May-18
    Jun-18
    Jul-18
    Aug-18
    Sep-18
    Oct-18
    Nov-18
    Dec-18
    Jan-19
    Feb-19
    Mar-19
    Apr-19

    This is the table I am trying to populate. I've already written the macro for it as you can see in Module 1. The problem I'm having is speed. The original data set has over 300,000 rows and this code takes over 30 seconds to run. This is just one section in one table and there are many tables to populate. I'm trying to see how others would approach tackling this type of problem. Please let me know if you require more information.

    ID Date Logged Date Resolved
    1 43123.40227 43123.46993
    2 41904.53954 43010.32183
    3 41941.54383 42873.2952
    4 42055.62597 42922.37431
    5 42067.59779 42922.33264
    6 42072.46549 43217.52677
    7 42072.47997 42993.49816
    8 42095.56847 43202.58617
    9 42103.46568 43067.52628
    10 42124.57968 42865.46007
    11 42129.62002 42922.55455
    12 42131.41234 43046.37365
    13 42139.46682 43201.48561
    14 42187.50344 43223.59108
    15 42262.42084 43243.4297
    16 42276.33565 42936.65436
    17 42276.4942 42922.37431
    18 42285.55539 43432.64684
    19 42296.6516 42922.33264
    20 42299.50698 42837.47481




    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Pepe Le Mokko; 04-08-2019 at 12:19 PM. Reason: Replaced quote tags with code tags

  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: How can I optimize my code

    This might save a couple of seconds

    Please Login or Register  to view this content.
    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
    03-11-2019
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    8

    Re: How can I optimize my code

    Hi Thank you for your response, with my old code it took about 26 seconds to run and with your adjusment about 21.5 seconds. I'm still positive there's something that can be done much faster than this.

  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: How can I optimize my code

    Yeah - I didn't think it would save much - 4.5 seconds is more than I thought though

  5. #5
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,641

    Re: How can I optimize my code

    @viettest
    Please use code tags around code (the # button) instead of quote tags.I changed them for you this time

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: How can I optimize my code

    Have you tired countifs using tables and structured references? I'd have thought they would be faster than VBA

  7. #7
    Registered User
    Join Date
    03-11-2019
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    8

    Re: How can I optimize my code

    So right now the table is populated with countifs to fill it out. That specific section maybe takes about 2-3 seconds to calculate but the problem is this worksheet has many tables all filled with mostly countif functions. The whole sheet takes around 25 seconds to calculate and my goal was to cut this time by using vba to populate the tables

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: How can I optimize my code

    I’m not saying it’s impossible to make the process faster with VBA but for formulas as simple as these, I’d bet against it. Excel formulas support multi threading and they’re natively faster than VBA. You can normally make sheets more responsive with VBA due to fewer formulas, to make it faster you usually need a conceptually different solution in VBA and you’re essentially replicating the countifs functions.

    I suspect that you can probably do this with get and transform, but I don’t Kobo W it well enough to advise whether it would be any faster

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

    Re: How can I optimize my code

    This may save another second or two:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    03-11-2019
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    8

    Re: How can I optimize my code

    Hi xladept first off thanks alot for your input with my code.

    After testing your code it brought the time down to 12.5 seconds! Which is awesome but I'm being very picky about speed. So I played around a bit more and found that using DateAdd was adding considerable time to the speed. I replaced
    Please Login or Register  to view this content.
    With
    Please Login or Register  to view this content.
    And the time is now at around 4.7-5 seconds. May be this is as good as it will get? I will try some more but your code helped me a lot thanks.

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

    Re: How can I optimize my code

    Good to hear!

    You're welcome and thanks for the rep!

    Maybe another split second with:

    Please Login or Register  to view this content.
    Last edited by xladept; 04-08-2019 at 05:02 PM. Reason: Speling

+ 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. Optimize code without Select
    By nordicdust in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-03-2019, 07:08 PM
  2. [SOLVED] Optimize my VBA code
    By modytrane in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-07-2019, 11:25 AM
  3. Need to optimize the code
    By pm.patel189 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-05-2018, 01:06 PM
  4. Optimize a code
    By pezalmendra in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-06-2015, 05:31 PM
  5. Optimize code
    By DarkKnightLupo in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 02-19-2014, 08:58 AM
  6. Optimize code
    By miso.dca in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-08-2011, 03:35 PM
  7. Optimize VBA code
    By doodlebug in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2007, 07:53 AM

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