+ Reply to Thread
Results 1 to 12 of 12

Lapping numbers using arrays and dictionary

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Lapping numbers using arrays and dictionary

    Hello everyone
    I have created the following code
    Please Login or Register  to view this content.
    The worksheet has columns from A to J with numbers .. and there are CODE numbers in M1 to V1
    The idea of the code is that to loop the data in columns A to J and if a CODE number found twice in two adjacent rows then: >>
    to store the two rows of spot and a row before and a row after
    Example:
    the CODE number 51 is in two rows 3 and 4 (these rows we can call it spot rows) , so we deal with the row before this spot which is row 2 and the row after this spot which is row 5
    So we deal in this case with rows from 2 to 5 >> then store in a dictionary any number except the numbers within the CODE numbers

    The code is working fine on the Sample attached as this is Sample but as for the original data which is about 3000 rows, it takes about a minute
    Is there a way to improve it ..? or what is in the code that makes the code runs slowly?
    Attached Files Attached Files
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Lapping numbers using arrays and dictionary

    Any help in this topic?

  3. #3
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Lapping numbers using arrays and dictionary

    I don't quite understand what you want.

    Example:
    the CODE number 51 is in two rows 3 and 4 (these rows we can call it spot rows) , so we deal with the row before this spot which is row 2 and the row after this spot which is row 5
    So we deal in this case with rows from 2 to 5 >> then store in a dictionary any number except the numbers within the CODE numbers
    Using this example, what is the result?

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Lapping numbers using arrays and dictionary

    The result is the numbers in the spot area + row before + row after >> stored in a dictionary to be counted and finally sorted from largest to smallest.
    As for the result, run the macro attached and you will get the result. The maco is working well but as for this small sample. The problem is that it is very slow as for the original data.

  5. #5
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Lapping numbers using arrays and dictionary

    The result is the numbers in the spot area + row before + row after
    Using this example, CODE number 51, I need you to show me the result (i.e the numbers) so I can understand what you want.
    I tried your file, I clear all CODE number and then I put 51 in M1, run your code and the result is 39 & 2, I don't understand why that is the result.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Lapping numbers using arrays and dictionary

    See if this works for your real data.

    Please Login or Register  to view this content.
    It assume the real data is just more of the same. That all the values are numerical.
    I testing on 20k dataset and the speed reduction is big.
    Cheers
    Andy
    www.andypope.info

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Lapping numbers using arrays and dictionary

    Thats amazing Andy
    The code takes about 4 seconds and very fast. Thank you very much for your great help.
    Best and Kind Regards

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,231

    Re: Lapping numbers using arrays and dictionary

    Hi Yasser...

    Wanna try a unorthodox method and give feedback...
    I removed your merged cells as I made use of a helper column...
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  9. #9
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Lapping numbers using arrays and dictionary

    Thanks a lot Sintek. This is very fast but the results not as the expected
    Try Andy's code or my code to see the results
    Attached Files Attached Files

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Lapping numbers using arrays and dictionary

    Please Login or Register  to view this content.
    Last edited by jindon; 05-17-2020 at 05:09 AM. Reason: Fixed a bug

  11. #11
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,231

    Re: Lapping numbers using arrays and dictionary

    My bad...Misunderstood...I assumed there would only be one occurrence of a duplicate number is the data set...

    I am assuming that where there are triplicates, both ranges are made use of...

    Range.png

    Results after all codes...

    Results.png

    Please Login or Register  to view this content.
    Last edited by sintek; 05-17-2020 at 04:28 AM.

  12. #12
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Lapping numbers using arrays and dictionary

    Thanks a lot for all of you.
    Really amazing and very fast solutions
    Best and Kind Regards for all of you.

+ 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. Vlookup with arrays and dictionary
    By kasan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-30-2018, 03:03 PM
  2. [SOLVED] Join 3 arrays/arraylist/ranges and pass them to dictionary
    By jaryszek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-09-2018, 07:49 AM
  3. [SOLVED] Dictionary or Scripting.Dictionary. Binding Referencing Dim-ing. Sub routines and Function
    By Doc.AElstein in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 07-12-2016, 08:28 AM
  4. [SOLVED] Comparing Arrays: What are tradeoffs b/w using a Dictionary vs a nested For-Each loops?
    By joe31623 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-04-2016, 01:29 PM
  5. [SOLVED] Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemObject
    By downtown1933 in forum Excel Programming / VBA / Macros
    Replies: 42
    Last Post: 10-01-2013, 04:38 AM
  6. Over Lapping Bubbles and Labels
    By Fullam in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 04-18-2006, 10:00 AM
  7. [SOLVED] Need a function that separates over-lapping work shift hours.
    By Katybug1964 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-24-2005, 11:06 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