+ Reply to Thread
Results 1 to 7 of 7

Fairly complex - matching "siblings" and "parents" across sheets

  1. #1
    Registered User
    Join Date
    12-01-2016
    Location
    Denmark
    MS-Off Ver
    Office 365 ProPlus
    Posts
    8

    Fairly complex - matching "siblings" and "parents" across sheets

    Hi all

    Tried to solve this problem using formulas which was manageable, but only by adding several helper columns and having a formula too complex for "normal" users to read and understand.
    So now I try to have it done with VBA instead.

    In short the task is to find pairs of "siblings" with the same parent. See enclosed workbook for illustration.

    Outcome
    Range with comments in sheet 1, column D

    Information
    Sheet 1 is the main sheet. This is where the matching should be done
    Sheet 2 contains all siblings. This sheet is used for identifying siblings

    Criteria
    • Column A in sheet 1 should contain more than one entry of the Top Item ID. E.g. 6083966 has 9 entries. If only one entry the function should return a comment e.g. "6083977 only one entry". (Highlighted in blue)
    • If more than one entry in column A sheet 1, next step is to check if the Item ID in column B. If the Item ID has duplicates in either column A or B in sheet 2, the function should return a comment "Multiple entries in Sheet 2" (Highlighted in orange)
    • If there is only one entry in either column A or B in sheet 2, the function should match the related sibling. E.g. Item ID 6023864 has a sibling in sheet 2, 6179298. This goes both ways so that for Item ID 6179298 the function should return sibling 6023864 (Highlighted in Yellow)
    • A pair of siblings should always have the same parent. E.g siblings 6023864 & 6179298 has the parent 6083966 = OK. But there is also a pair of siblings with different parents = Not OK (highlighted in red)
    • If a pair of siblings have the same parent last step is to check if the pair of siblings have both texts "Only Eng" & "Only Supp". If not = Not OK (highlighted in grey)
    • Examples of successful matches are highlighted in green.

    My biggest problem so far with this problem is speed and ensuring all criteria is met. Main sheet 1 can contain anywhere from 2000 rows up to 20000 rows to be checked. Sheet 2 contains anywhere from 2000 rows up to 6000 rows.
    I am thinking populating the ranges in arrays and doing the comparing there would be the fastest approach.

    Looking forward to hearing from you.
    Attached Files Attached Files

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Fairly complex - matching "siblings" and "parents" across sheets

    Just to be clear.

    Sheet1 column A is the list of parents
    Sheet1 column B is the list of children

    Good children have only one parent.
    You want to identify bad children and any child who has a bad sibling.

    Siblings with different "only Eng" entires are a separate way to be not-completely-good

    Is that the case.

    (I can't work on this until this afternoon after work, but it sounds like a fun problem)
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    12-01-2016
    Location
    Denmark
    MS-Off Ver
    Office 365 ProPlus
    Posts
    8

    Re: Fairly complex - matching "siblings" and "parents" across sheets

    Ideally I just want to know the good combinations, the rest is irrelevant, at least on paper . I do find it useful though to add a comment as to why they are "bad". E.g "two entries in sheet 2" etc.
    A good pair of siblings have the same parent in column A, and one of the siblings has the comment "Only Eng" while the other has the "Only Supp" comment

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Fairly complex - matching "siblings" and "parents" across sheets

    So "Only Eng" + "Only Supp" is good.
    Otherwise is bad.

    A child with no siblings is bad
    A child with more than one sibling is bad.

    Is that correct?

    Might a child/parent pair be listed twice? (or do you want that flagged.)

  5. #5
    Registered User
    Join Date
    12-01-2016
    Location
    Denmark
    MS-Off Ver
    Office 365 ProPlus
    Posts
    8

    Re: Fairly complex - matching "siblings" and "parents" across sheets

    Yes in order for a pair of siblings to be "good" the pair needs to have both "Only Eng" + "Only Supp"
    A child with no sibling = bad. No entries would be found in the table in sheet 2 so this would be an orphan
    A child with more than one sibling = bad. If a child is present more than once in the table in sheet 2, this should be disregarded.
    A child/parent pair will be unique. You can have one parent with multiple sets of siblings. But there should never be more than one pair of siblings with the same parent more than once.
    A pair of siblings can have different parents also, which is ok. As long as the pair has both texts.

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Fairly complex - matching "siblings" and "parents" across sheets

    I've got something, but my testing encountered a problem

    In your data 6023864 has multiple parents, 6083966,6083977,6083968,6083967,6083888
    Yet you have it marked as good.

  7. #7
    Registered User
    Join Date
    12-01-2016
    Location
    Denmark
    MS-Off Ver
    Office 365 ProPlus
    Posts
    8

    Re: Fairly complex - matching "siblings" and "parents" across sheets

    • Yes this is also ok, as long as the sibling 6179298 is found and that they both have the same parent.
    • Parent 6083966 has a pair of kids 6023864 (Only Supp) & 6179298 (Only Eng). So this is a good relationship (marked in green)
    • The second time 6023864 appears it is with parent 6083977. As this parent is only present once in column A in sheet 1, the relationship is incomplete (marked in blue)
    • Third time 6023864 appears it has parent 6083968. Siblings of 6023864 can be found, but not with the same parent.
    • Another good relationship would be parent 6083967 with siblings 6023864 & 6179298.
    • The last relationship with parent 6083888 is not ok, as the text belonging to each sibling is the same. In this case "Only Supp"

    I was thinking if it might be an idea to sort the data according to the Top Item ID and then for each parent check if good relationships exist? Once the search within one parent is done, repeat the loop with the second parent.

+ 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. Replies: 5
    Last Post: 02-05-2019, 12:03 AM
  2. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  3. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  4. Replies: 2
    Last Post: 06-06-2013, 12:45 PM
  5. "The "sheets" method from the "_Global" object have failed."
    By mankit87 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-08-2011, 08:53 AM
  6. Replies: 7
    Last Post: 05-13-2006, 05:02 PM
  7. Replies: 1
    Last Post: 01-30-2006, 06:10 PM

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