+ Reply to Thread
Results 1 to 16 of 16

Comparing two ranges and returning a match

  1. #1
    Registered User
    Join Date
    01-19-2010
    Location
    Finland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Comparing two ranges and returning a match

    Hey there,

    I need a function to compare two ranges and return a match. For example

    Range A: {A56, B43, C98, D44}
    Range B: {A33, G89, D44, K123, OB55}

    the function would return D44. Is it possible at all with functions or do I need a macro?

    Thank you in advance!
    -MachtiSonni

  2. #2
    Registered User
    Join Date
    07-27-2006
    MS-Off Ver
    MS Office 2007
    Posts
    79

    Re: Comparing two ranges and returning a match

    macro not required.

    hope this helps
    Attached Files Attached Files
    TL

    https://sites.google.com/site/teelim/
    My page of "not so useful" spreadsheets

  3. #3
    Registered User
    Join Date
    01-19-2010
    Location
    Finland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Comparing two ranges and returning a match

    Quote Originally Posted by teelim View Post
    macro not required.

    hope this helps
    Thank you, but not quite what I'm looking for. I need to compare the whole two ranges to each other. Not just one value. If ANY of the cells in range A matches ANY of the cells in range B.

    I guess I could do that with multiple nested IF-functions.

  4. #4
    Registered User
    Join Date
    07-27-2006
    MS-Off Ver
    MS Office 2007
    Posts
    79

    Re: Comparing two ranges and returning a match

    it does compare the whole range.

    put your data in Col A and Col B, then copy and drag the formula in Col C to the bottom (to the last data at Col A)

    all the data that match will show up in Col C

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Comparing two ranges and returning a match

    Here, try this:

    =INDEX(A:A,MATCH(FALSE(),ISNA(MATCH(A:A,B:B,0)),0))

    comfirmed with ctrl+shift+enter

    This will return you first value that match or #N/A if there is no match

  6. #6
    Registered User
    Join Date
    01-19-2010
    Location
    Finland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Comparing two ranges and returning a match

    Quote Originally Posted by teelim View Post
    it does compare the whole range.

    put your data in Col A and Col B, then copy and drag the formula in Col C to the bottom (to the last data at Col A)

    all the data that match will show up in Col C
    Oh, true. Didn't get that. Cheers!

  7. #7
    Registered User
    Join Date
    01-19-2010
    Location
    Finland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Comparing two ranges and returning a match

    Quote Originally Posted by zbor View Post
    Here, try this:

    =INDEX(A:A,MATCH(FALSE(),ISNA(MATCH(A:A,B:B,0)),0))

    comfirmed with ctrl+shift+enter

    This will return you first value that match or #N/A if there is no match
    Ummm...I can't get it to work. It returns #N/A even if I definately do have a match at the ranges. And yes, I used ctrl-shift-enter for an array formula...

  8. #8
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Comparing two ranges and returning a match

    I don't know why.. Look here:

    Book1(1).xls

    Cell D1 returns first
    Cell E1 count how many there is matching values

  9. #9
    Registered User
    Join Date
    01-19-2010
    Location
    Finland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Comparing two ranges and returning a match

    Quote Originally Posted by zbor View Post
    I don't know why.. Look here:

    Attachment 63228

    Cell D1 returns first
    Cell E1 count how many there is matching values
    Weird...seems like an exact copy of the one I put in and now it works...But thank you very much, both of you! You've been very helpful.

    Just for possible future reference, is there an easy way to return an array of all the matches here? Surely by coding, but with a function?

  10. #10
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Comparing two ranges and returning a match

    You can use teelim approach and in first row put FILTER and filter out blanks.

    However, rather than VLOOKUP use MATCH function:

    =IF(ISNA(MATCH(A1;$B:$B;0));"";A1)

    and pull down

    (change ; to , if needed)

  11. #11
    Registered User
    Join Date
    10-21-2009
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Comparing two ranges and returning a match

    Hi

    Sorry to barge in on your thread, but this solved a problem I was having, but it has created another!

    The formula you have created works fine in Excel 2007, but always returns #N/A in 2003. Have you any idea why this is?

    We use both versions in our company as we are very large and transitioning is taking time. I run both versions on my PC and there is no conflict as far as I can see and my IT dept confirmed that the two versions will not conflict.

    Thanks for any ideas on this.

  12. #12
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Comparing two ranges and returning a match

    Attachment I put above is saved for XL 2003 and it should work. Can you open it and check?

  13. #13
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Comparing two ranges and returning a match

    hi jkr6064
    you could highlight the differences
    Please Login or Register  to view this content.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  14. #14
    Registered User
    Join Date
    10-21-2009
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Comparing two ranges and returning a match

    Hi zbor

    thanks but no, I opened it in xl2003 and on the cell with the formula, pressed F2 to activate the cell, then shift+ctrl+enter as normal for array and it returned #N/A

    pike - thanks for suggestion, but this is more of a head scratcher for me to understand why a striaghtforward formula works in 2007 but not 2003. I could add the code, but I'd still have that nagging thing in my head to why the formula won't work!!!

  15. #15
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Comparing two ranges and returning a match

    In that case I would suggest to open new thread due to rule no 2

    2. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

    Edit: try to put ranges A1:A1000 instead of A:A (for all ranges)

  16. #16
    Registered User
    Join Date
    01-19-2010
    Location
    Finland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Comparing two ranges and returning a match

    Quote Originally Posted by zbor View Post
    I don't know why.. Look here:

    Attachment 63228

    Cell D1 returns first
    Cell E1 count how many there is matching values
    Okay,

    now I really started using this. I found out the weirdest error. When I open up the attachment it works allright. But when I change anything and I mean anything at all it starts giving me #N/A. For example if I add "G43" to cell A11 it gives me #N/A to cell D1...

+ 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