+ Reply to Thread
Results 1 to 13 of 13

Matching and copying repeated values based on root value - code works but very slow

  1. #1
    Registered User
    Join Date
    12-30-2012
    Location
    East Coast, USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Matching and copying repeated values based on root value - code works but very slow

    I have working code to solve my data issue, my problem is that my data set is enormous and my code is way too slow and inefficient to run in an appropriate time frame (it's taking many many hours to complete).

    I have two sets of data and I need to match them based on a "root" value to create a mapping. I'll explain what I mean by "root" value here with a basic data scenario...

    Data Set 1:
    PRA7854.0
    PRA7854.1
    PRA7854.2
    EVA1125.0
    EVA1125.1
    EVA1125.2

    Data Set 2:
    PRA7854.SS1.0
    EVA1125.SS2.2

    In the above data sets the root values would be PRA7854 and EVA1125. So the final data map, in this basic scenario, would look like this:

    Data map:
    PRA7854.0 PRA7854.SS1.0
    PRA7854.1 PRA7854.SS1.0
    PRA7854.2 PRA7854.SS1.0
    EVA1125.0 EVA1125.SS2.2
    EVA1125.1 EVA1125.SS2.2
    EVA1125.2 EVA1125.SS2.2

    But there's one more wrench: the data maps one to many. Here's a more accuracte data scenario...

    Data set 1:
    PRA7854.0
    PRA7854.1
    PRA7854.2
    EVA1125.0
    EVA1125.1
    EVA1125.2

    Data set 2:
    PRA7854.SS1.0
    PRA7854.SS1.1
    PRA7854.SS1.2
    EVA1125.SS1.0
    EVA1125.SS2.0
    EVA1125.SS2.1

    So in the above data sets the root values are still PRA7854 and EVA1125 but the final data map would need to look like this:

    Data map:
    PRA7854.0 PRA7854.SS1.0
    PRA7854.0 PRA7854.SS1.1
    PRA7854.0 PRA7854.SS1.2
    PRA7854.1 PRA7854.SS1.0
    PRA7854.1 PRA7854.SS1.1
    PRA7854.1 PRA7854.SS1.2
    PRA7854.2 PRA7854.SS1.0
    PRA7854.2 PRA7854.SS1.1
    PRA7854.2 PRA7854.SS1.2
    EVA1125.0 EVA1125.SS1.0
    EVA1125.0 EVA1125.SS2.0
    EVA1125.0 EVA1125.SS2.1
    EVA1125.1 EVA1125.SS1.0
    EVA1125.1 EVA1125.SS2.0
    EVA1125.1 EVA1125.SS2.1
    EVA1125.2 EVA1125.SS1.0
    EVA1125.2 EVA1125.SS2.0
    EVA1125.2 EVA1125.SS2.1

    As you can see, the values of Data set 1 need to be repeated for as many matching root values there are in Data set 2. I've already accomplished this as well as adding the root value (with manually doing Text-to-columns and a countif formula), so my prepared data sets look like this (I have removed some records from data set 1 just to reduce the length of my post):

    Data Set 1:
    AA284.0 AA284
    AA284.0 AA284
    AA284.0 AA284
    AA284.0 AA284
    AA284.0 AA284
    AA284.0 AA284
    AA284.0 AA284
    AA284.0 AA284
    AA284.1 AA284
    AA284.1 AA284
    AA284.1 AA284
    AA284.1 AA284
    AA284.1 AA284
    AA284.1 AA284
    AA284.1 AA284
    AA284.1 AA284
    AA30.0 AA30
    AA30.0 AA30
    AA30.0 AA30
    AA30.0 AA30
    AA336.0 AA336
    AA337.0 AA337
    AA337.0 AA337
    AA337.0 AA337
    AA337.0 AA337
    AA337.0 AA337
    AA337.0 AA337
    AA337.1 AA337
    AA337.1 AA337
    AA337.1 AA337
    AA337.1 AA337
    AA337.1 AA337
    AA337.1 AA337
    AA8.0 AA8
    EVA1176.0 EVA1176
    EVA1192.0 EVA1192
    EVA1225.0 EVA1225
    EVA1225.0 EVA1225
    EVA1225.0 EVA1225

    Data Set 2:
    AA284.SS1.0 AA284
    AA284.SS2.0 AA284
    AA284.SS2.1 AA284
    AA284.SS3.0 AA284
    AA284.SS3.1 AA284
    AA284.SS3.2 AA284
    AA284.SS4.0 AA284
    AA284.SS4.1 AA284
    AA30.SS31.0 AA30
    AA30.SS32.0 AA30
    AA30.SS32.1 AA30
    AA30.SS33.0 AA30
    AA30.SS33.1 AA30
    AA30.SS34.0 AA30
    AA30.SS35.0 AA30
    AA30.SS36.0 AA30
    AA336.SS1.0 AA336
    AA337.SS1.0 AA337
    AA337.SS2.0 AA337
    AA337.SS3.0 AA337
    AA337.SS3.1 AA337
    AA337.SS3.2 AA337
    AA337.SS3.3 AA337
    AA8.SS9.0 AA8
    EVA1176.PS1.0 EVA1176
    EVA1192.PS1.0 EVA1192
    EVA1225.PS1.0 EVA1225
    EVA1225.PS10.0 EVA1225
    EVA1225.PS10.1 EVA1225
    EVA1225.PS10.2 EVA1225
    EVA1225.PS11.0 EVA1225
    EVA1225.PS12.0 EVA1225
    EVA1225.PS13.0 EVA1225
    EVA1225.PS14.0 EVA1225
    EVA1225.PS15.0 EVA1225
    EVA1225.PS2.0 EVA1225
    EVA1225.PS3.0 EVA1225
    EVA1225.PS4.0 EVA1225
    EVA1225.PS5.0 EVA1225
    EVA1225.PS6.0 EVA1225
    EVA1225.PS7.0 EVA1225
    EVA1225.PS8.0 EVA1225
    EVA1225.PS9.0 EVA1225


    The code below will create the final data map desired by filtering on the root value from set 1 on set 2 and copying the related value back to set 1. The issue is the autofilter is slow and this is only exacerbated by the fact data set 1 is almost 32,000 rows and data set 2 is almost 10,000 records. If anyone has any ideas on how to make my code faster/more efficient or has an alternative ideas it'd be most appreciated.

    My code:
    Please Login or Register  to view this content.
    Last edited by phishie; 12-30-2012 at 11:09 PM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Matching and copying repeated values based on root value - code works but very slow

    Try this. It reads your raw data Data Set 1 from column A Sheet1 and Data Set 2 from column B Sheet1 then outputs the Data Map to column C Sheet1. It doesn't use the "prepared" data sets.

    Please Login or Register  to view this content.

  3. #3
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Matching and copying repeated values based on root value - code works but very slow

    I have taken a different approach to your problem (using Collection objects). The enclosed workbook contains 3 worksheets.

    - Dataset1,
    - Dataset2,
    - Result

    When you run the routine "pub_sub_BuildCombinedDataSet()" the Result worksheet will be populated with the combined results of dataset1 and dataset2 as per the requested logic. There is one constraint, the entries in the dataset worksheets must be in a sorted order!

    I do not have the amount of rows that you have so the performance in difficult to test. Using a test data set of 50 entries in dataset1, 70 entries in dataset2 and a resulting combined dataset of 2,072 rows takes about 0.09 seconds.

    I would say, give it a try if you want to

    PS: This solution also does not depend on the prepared datasheets
    Attached Files Attached Files
    Last edited by OllieB; 12-31-2012 at 03:49 AM.
    If you like my contribution click the star icon!

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Matching and copying repeated values based on root value - code works but very slow

    Olaf,
    When I click to open the attached, I have got the following error
    Invalid Attachment specified. If you followed a valid link, please notify the administrator

  5. #5
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Matching and copying repeated values based on root value - code works but very slow

    @AB33,

    Strange. I have enclosed the file once more in this post itself. Can you please let me know if the link works.

    MergeDataSets.xlsm

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Matching and copying repeated values based on root value - code works but very slow

    Olaf,
    It is now!

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

    Re: Matching and copying repeated values based on root value - code works but very slow

    Try this
    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    12-30-2012
    Location
    East Coast, USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Matching and copying repeated values based on root value - code works but very slow

    Olaf.Braxhoofden, your code works beautifully. Thank you again, this is a tremendous help.

    I ran it against my full data set and it takes less than a minute, unbelievably quick.

    I even ran it in reverse, as in I swapped the data in Set 1 and Set 2 to get the reverse mapping, and it worked just as well and just as quickly.

    Thank you again.

  9. #9
    Registered User
    Join Date
    12-30-2012
    Location
    East Coast, USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Matching and copying repeated values based on root value - code works but very slow

    Correction, it takes less than 2 SECONDS to complete. Quite an improvement

  10. #10
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Matching and copying repeated values based on root value - code works but very slow

    I must admit, I am quite happy with the speed of my solution. I assume your problem is solved?

  11. #11
    Registered User
    Join Date
    12-30-2012
    Location
    East Coast, USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Matching and copying repeated values based on root value - code works but very slow

    Yup, thanks again.

  12. #12
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Matching and copying repeated values based on root value - code works but very slow

    A little faster solution

    Please Login or Register  to view this content.
    Last edited by mike7952; 01-01-2013 at 02:47 PM.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  13. #13
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Matching and copying repeated values based on root value - code works but very slow

    Hi Phishie,

    if you replace the following code

    Please Login or Register  to view this content.
    with

    Please Login or Register  to view this content.
    you should see a further performance improvement
    Last edited by OllieB; 01-01-2013 at 02:58 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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