+ Reply to Thread
Results 1 to 22 of 22

Compare ANY cells that match in two ranges (UDF)

  1. #1
    Registered User
    Join Date
    12-06-2015
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    35

    Compare ANY cells that match in two ranges (UDF)

    Hello Guys,

    Can the below UDF be modified (corrected) to give an *exact* match of ANY cell in one range to ANY cell in another range? There can be repeats in both ranges. There can be more than one match and that is ok.

    Match any cell in B1:B9 to any cell in A1:A9 and give result at C9 or wherever.

    E.g. B2 & B8 plus A1 & A8 repeat and is ok.

    Result: A2 and B5 match so result "Yes" at C9

    ----A----B-----------C
    1 110 127
    2 334 222
    3 645 509
    4 250 651
    5 822 334
    6 711 453
    7 800 766
    8 110 222
    9 984 516 Result "Yes"

    The results from the below UDF are not always accurate.

    Please Login or Register  to view this content.
    As well as a UDF I would also appreciate a normal formula for above if possible.

    Thanks

    Lapper

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Compare ANY cells that match in two ranges (UDF)

    Try this formula...
    =IF(SUMPRODUCT(COUNTIF(A1:A9,B1:B9))>0,"Yes","")
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    12-06-2015
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Compare ANY cells that match in two ranges (UDF)

    Many thanks FDibbins. Exactly right.

    Any luck with the UDF?


    Lapper

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Compare ANY cells that match in two ranges (UDF)

    if you are after EXACT then your find needs to be
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    also
    do you have an example of an inaccurate answer?
    Last edited by humdingaling; 05-04-2016 at 03:19 AM.
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  5. #5
    Registered User
    Join Date
    12-06-2015
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Compare ANY cells that match in two ranges (UDF)

    Just create 2 ranges at say A1:A10 and B1:B10 using for example
    Please Login or Register  to view this content.
    as the values
    then at C10 use the UDF original code 'AnyMatch' and just keep recalculating and you will see the inaccuracies.

    Using the same ranges as above your modified code only gives "NO" for me

    Thanks

    Lapper

    [Edit].... I should have added that if you copy the ranges, with the random values, and then paste them as values only elsewhere then try the code, it will then be accurate. My requirement is for random values.
    Last edited by Lapper; 05-04-2016 at 05:11 AM.

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Compare ANY cells that match in two ranges (UDF)

    try adding
    Application.Volatile at the start of the UDF

  7. #7
    Registered User
    Join Date
    12-06-2015
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Compare ANY cells that match in two ranges (UDF)

    No....Makes no difference.

  8. #8
    Registered User
    Join Date
    12-06-2015
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Compare ANY cells that match in two ranges (UDF)

    Anybody else care to try to *fix* the UDF code?

    Thanks

    Lapper

  9. #9
    Registered User
    Join Date
    12-06-2015
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Compare ANY cells that match in two ranges (UDF)

    I would also like a formula for this. Match EVERY cell in one range to ANY cell in another range.
    There can be repeats in both ranges. There can be more than one match and that is ok.

    Match EVERY cell in B1:B9 to ANY cell in A1:A9 and give result at C9 or wherever.

    E.g. There could be repeats in column A and column B and that is ok.

    Result: Every cell in B1:B9 has a match in A1:A9 so result "Yes" at C9

    ----A----B-----------C
    1 110 645
    2 334 250
    3 645 711
    4 250 800
    5 822 110
    6 711 800
    7 800 334
    8 268 984
    9 984 645 Result "Yes"

    Thanks
    Last edited by Lapper; 05-04-2016 at 06:50 PM.

  10. #10
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Compare ANY cells that match in two ranges (UDF)

    Please Login or Register  to view this content.

    add lookin:=xlvalues to .find

  11. #11
    Registered User
    Join Date
    12-06-2015
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Compare ANY cells that match in two ranges (UDF)

    Thank you very much hum.............That fixed it

    Any answer to #9?

    Lapper

  12. #12
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Compare ANY cells that match in two ranges (UDF)

    Not really sure why you would want a UDF for this, when a formula will probably be quicker and more efficient?

  13. #13
    Registered User
    Join Date
    12-06-2015
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Compare ANY cells that match in two ranges (UDF)

    Yes sorry. I mean I want a formula.


    Lapper

  14. #14
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Compare ANY cells that match in two ranges (UDF)

    Does my formula from post 2 not do that for you?

  15. #15
    Registered User
    Join Date
    12-06-2015
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Compare ANY cells that match in two ranges (UDF)

    No. See below

    EVERY or EACH cell in B1:B9 must match ANY cell in A1:A9

    As stated there can be repeats in each range.



    ----A----B-----------C
    1-- 1-- 1
    2-- 2-- 2
    3-- 3-- 3
    4-- 4-- 800
    5-- 5-- 5
    6-- 6-- 6
    7-- 7-- 7
    8-- 8-- 8
    9-- 9-- 9 Result "Yes" But should be "No"
    10--
    11--

    800 doesn't match ANY cell in A1:A9

    Thanks

    Lapper

  16. #16
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Compare ANY cells that match in two ranges (UDF)

    To best describe or illustrate your problem you would be better off attaching a dummy workbook. The workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.

  17. #17
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,910

    Re: Compare ANY cells that match in two ranges (UDF)

    Quote Originally Posted by Lapper View Post
    Result "Yes" But should be "No"
    Try...
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    12-06-2015
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Compare ANY cells that match in two ranges (UDF)

    Here it is................ I hope
    Attached Files Attached Files

  19. #19
    Registered User
    Join Date
    12-06-2015
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Compare ANY cells that match in two ranges (UDF)

    Thanks for the new UDF Phuocam

    That is a bonus (and works) because we are now after a formula.

    See the attached sheet at #18

    Thanks

  20. #20
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,910

    Re: Compare ANY cells that match in two ranges (UDF)

    Quote Originally Posted by Lapper View Post
    Here it is...I hope
    Try this formula in C9:

    =IF(MIN(COUNTIF(A1:A9,B1:B9))>0,"Yes","")

    Enter with Ctrl+Shift+Enter.

  21. #21
    Registered User
    Join Date
    12-06-2015
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Compare ANY cells that match in two ranges (UDF)

    Yes that works perfectly Phuocam

    Thank you for that.

    Lapper

  22. #22
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,910

    Re: Compare ANY cells that match in two ranges (UDF)

    You're 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. Compare multiple cells to see if they match exactly
    By redwine in forum Excel General
    Replies: 12
    Last Post: 08-24-2016, 11:28 PM
  2. Macro to compare text in ranges to find match and replace with adjacent value.
    By 54ed in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2013, 06:44 PM
  3. Compare range with previous ranges,display elapsed row match
    By sans in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-19-2013, 12:08 PM
  4. Replies: 6
    Last Post: 05-30-2012, 03:09 PM
  5. Need function to compare cells/ranges
    By arun22 in forum Excel General
    Replies: 16
    Last Post: 04-09-2012, 10:06 AM
  6. compare two Ranges in Excel and highlight the cells that are different
    By zhshqzyc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-26-2011, 10:47 AM
  7. Compare two cells (Partial Match)
    By manny_cb in forum Excel General
    Replies: 1
    Last Post: 07-11-2008, 11:28 AM
  8. Compare Ranges/Return Specific Value for Matching Cells
    By orutulsa in forum Excel General
    Replies: 1
    Last Post: 01-12-2008, 02:53 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