+ Reply to Thread
Results 1 to 25 of 25

Code using dictionary class is too slow- need it work faster if possible.

  1. #1
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Code using dictionary class is too slow- need it work faster if possible.

    I have come up with a code using three scripting dictionaries. It draws from data in a worksheet that currently contains upwards of 12,000 rows.

    It also inserts a formula (value of result) in a column for each row of this data.

    Currently, when I run it excel almost crashes. Eventually it gets there, so it works, but it takes quite a while to work.

    I could run each element of the code in separate Subs, but this is far from ideal as a solution.

    So I am looking for a way to speed up the current code if possible.

    here is the code:

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: Code using dictionary class is too slow- need it work faster if possible.

    For a start.....at the top of the macro put:

    Please Login or Register  to view this content.
    and at the end put

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Re: Code using dictionary class is too slow- need it work faster if possible.

    Thanks swoop99 but that seemed to slow it down then crash excel!

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Code using dictionary class is too slow- need it work faster if possible.

    Hi Strud
    could you upload a file with an example of your original data and the desired result

  5. #5
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Code using dictionary class is too slow- need it work faster if possible.

    I do not know why you loop through vData twice:
    Please Login or Register  to view this content.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  6. #6
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Re: Code using dictionary class is too slow- need it work faster if possible.

    Because with the second dic the keys will be different- as they are added when 'Parent' is NOT any of the criteria:

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Re: Code using dictionary class is too slow- need it work faster if possible.

    Quote Originally Posted by nilem View Post
    Hi Strud
    could you upload a file with an example of your original data and the desired result
    Thanks nilem.

    I always try to upload a sample workbook but desensitising the data would take far too long and building a sample wouldn't really adequately show what I'm trying to achieve.

    So unfortunately can't do so here.

  8. #8
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Code using dictionary class is too slow- need it work faster if possible.

    I think you misunderstand. Those criteria are simply the Else clause of the first criteria. If Parent matches one of the criteria add to dic; if it does not, add to dic2. There is no use to loop twice through everything.

  9. #9
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Re: Code using dictionary class is too slow- need it work faster if possible.

    Ah I see.

    Sorry I missed that part. Thanks Izandol that does speed it up a little bit.

  10. #10
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Code using dictionary class is too slow- need it work faster if possible.

    I am not sure the code is at fault - if you comment the formula line, is the speed much better?

  11. #11
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Re: Code using dictionary class is too slow- need it work faster if possible.

    comment the formula line? Not sure I follow what you mean...

  12. #12
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Code using dictionary class is too slow- need it work faster if possible.

    Change this part:
    Please Login or Register  to view this content.
    to this:
    Please Login or Register  to view this content.
    then try the code.

  13. #13
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Re: Code using dictionary class is too slow- need it work faster if possible.

    Yeah the speed is much, much better.

    Almost instantaneous. So it must be the formula part.

  14. #14
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Re: Code using dictionary class is too slow- need it work faster if possible.

    oddly when I put the formula in manually and double click to fill down it works relatively quickly.

    Any ideas how I might do it quicker via VBA?

  15. #15
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Code using dictionary class is too slow- need it work faster if possible.

    I am not certain without a file - are contents of first two dictionaries going into the named ranges referred in the formula?

  16. #16
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Re: Code using dictionary class is too slow- need it work faster if possible.

    yeah thats right, the contents of the first two dictionaries go into the named ranges within the formula: 'Multiples_Valid_List' and 'Multiples_Invalid_List'.

  17. #17
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Re: Code using dictionary class is too slow- need it work faster if possible.

    Yeah that's right

  18. #18
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Code using dictionary class is too slow- need it work faster if possible.

    Do you wish to do exact comparison with column H or will values be contained within other text? If it is exact, I think it may be quicker to loop through the column and test each dictionary with Exists.

  19. #19
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Re: Code using dictionary class is too slow- need it work faster if possible.

    It is not an exact comparison, I had to use this formula because I am looking for a very distinct type of match:

    Please see my earlier post:

    http://www.excelforum.com/excel-form...ml#post3564622

  20. #20
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Code using dictionary class is too slow- need it work faster if possible.

    Will one list be much shorter than the other, or will they be similar number of items each one?

  21. #21
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Re: Code using dictionary class is too slow- need it work faster if possible.

    The valid list will always be a lot shorter

  22. #22
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Code using dictionary class is too slow- need it work faster if possible.

    In this case it may help to short circuit the formula when the valid items are not found - unless they will usually be present?

    Please Login or Register  to view this content.

  23. #23
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Re: Code using dictionary class is too slow- need it work faster if possible.

    Good thinking!

    That does make it a a lot faster. There's still a fair bit of processing time, but excel doesn't start 'Not Responding' and it is definitely quicker.

    Thanks for you patience with helping Izandol.

    Much appreciated

  24. #24
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Re: Code using dictionary class is too slow- need it work faster if possible.

    I guess it is always going to take a certain amount of time- so I think that's probably as streamlined as it may be- so I'll mark it as solved- thanks again

  25. #25
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Code using dictionary class is too slow- need it work faster if possible.

    You are welcome.

+ 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. Make the below code work faster!!!
    By devpp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-04-2013, 06:13 AM
  2. [SOLVED] Running VBA in excel is too slow, how to make it faster?
    By rsbuslon in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2013, 05:55 AM
  3. Moving a col from one location to another using vba ......really slow.....can faster
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-29-2011, 10:51 AM
  4. Faster alternative to dictionary object?
    By gpotter_htg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-21-2011, 05:09 PM
  5. Can anyone optimize the code? (to make it work faster)
    By olegai in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-23-2007, 07:50 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