+ Reply to Thread
Results 1 to 9 of 9

Compare 2 Arrays

  1. #1
    Registered User
    Join Date
    12-22-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Question Compare 2 Arrays

    Hi guys

    I've always been able to figure out what I need to do in Excel, but this one has got me stumped. Basically, I have two arrays, and I need to return back the common values. For example:
    Please Login or Register  to view this content.
    In this example, 4 and 9 are the common values. Yes they're also the same index and that can be optional for me (ie if there's a way to do it when they're not the same index then it's not a problem too). I need to be able to return and display something like "4 9" to a cell.

    How to do this?

    Thanks guys

  2. #2
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Compare 2 Arrays

    Really don't think it's possible. No way to concatenate constants of an array in my opinion...
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

  3. #3
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Akron, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Compare 2 Arrays

    There may be easier methods, but I'd do something like this:

    I'm filling the arrays with your values; you can fill them however you want to the key is the comparisons in the loop, notice the string will not get written to C if it's not equal or if it's 0.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-22-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Compare 2 Arrays

    OK, thanks. So there's no built in function... poop

    You'll have to forgive me, but VB scripting isn't my strong point. I can get what code you have written to create a little pop up window with the result, but I can't get it to enter it in to a cell. I know I'm doing something wrong, but I don't know what.

    Also, what would be the best ways of passing the arrays to the function? Individually or each array at a time?

    Thanks again

  5. #5
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Akron, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Compare 2 Arrays

    where are the arrays coming from?
    where are they in your worksheet?
    where do you want the result to go?
    will it always go to the same cell location?

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-22-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Compare 2 Arrays

    There are many arrays in a table. I'm basically experimenting with using Excel to solve some puzzles. I'm wondering if I'd have been better off doing it with PHP since that's my forte.

    Basically, there are 9 arrays in L2:T2 through L10:T10 (stacked on top of each other) and another 9 in B12:B20 through J12:J20, alongside each other. Where they all meet (ie between B2 and J10) is where I want the comparison doing.

    Does that help?

  7. #7
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Akron, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Compare 2 Arrays

    Sounds like they are basically cell values that you are calling an array?
    You could pass the ranges to the sub and use the ranges as the arrays.

    You may want to post an example workbook.

    You may also want to look at the Intersect method

    http://msdn.microsoft.com/en-us/library/bb209961.aspx

  8. #8
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Compare 2 Arrays

    I smell Sudoku!

    try this for size, not your final solution, but maybe a step in the right direction:

    select cells A1 to I1 and with these cells selected, put this in A1

    ={0,0,0,4,0,0,7,8,9}={1,0,0,4,0,0,0,0,9}

    then confirm with Ctrl-Shift-Enter

    the result will be

    Please Login or Register  to view this content.
    This kind of array formula can be incorporated into a bigger picture or other formula, but it might help if you could post your workbook, specifying which results you want to see where, based on what input and what logic.
    Last edited by teylyn; 12-22-2009 at 08:23 AM.

  9. #9
    Registered User
    Join Date
    12-22-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Compare 2 Arrays

    Ooo, that's interesting, that might be what I'm looking for... give me a mo and I'll get back to you, thanks

+ 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