0

I have a problem that seems pretty easy, but still cannot find a proper solution, I want to avoid using vba.

I have two tables in one spreadsheet. both have the same columns - Name, City, Province. My goal is compare both and if three out of three values in a row match, then pull "1", if not, pull 0.

I have used the formulas below , but it does not work for my case .

=IF(AND(A2=P:P,G2=M:M,H2=L:L),1,0)

=INDEX(A:P,MATCH(A2,P:P,FALSE),MATCH(G2,M:M,FALSE),2)

=INDEX(L:P,MATCH(A5,P:P,0),MATCH(G5,M:M,0),MATCH(H5,L:L,0))

=SUMPRODUCT(--(L2:L60=H2),--(M2:M60=G2),--(P2:P60=A2),B2:B60)

It seems that the solution is quiet simple , but I cannot find it,

Thanks in advance!

1
  • Thank for the reply! I compare rows with rows in these two tables. I will add the picture of a result - if matches . Can you please add this as an answer please? Commented May 29, 2019 at 13:17

2 Answers 2

1

The key here is to merge the columns together, them Match on that.

Like this

=IFERROR( IF( MATCH(H3&"_"&I3&"_"&J3, $C$2:$C$60&"_"&$B$2:$B$60&"_"&$A$2:$A$60,0), "Yes"), "No")

Choose a seperator character that doesn't otherwise appear in your data (I've chosne _)

Sign up to request clarification or add additional context in comments.

Comments

0

Assumption: Values just need to exist, not that they need to be of equivalent row.

=If(IfError(Match(A2,P:P,0),0)*IfError(Match(G2,M:M,0),0)*IfError(Match(H2,L:L,0),0)>0,1,0)

For each IfError, you will output a row number (>0) if you match, or if there is no match a zero will be output. Multiply anything by zero and you get zero, whcih allows a 1 or 0 output for true/false in the overarching If-statement.


If they need to be of the same row, you can compare 2 matches, which rely on the transitive property (A=B, B=C, so A=C):

=If(And(Match(A2,P:P,0)=Match(G2,M:M,0),Match(G2,M:M,0)=Match(H2,L:L,0)),1,0)

Edit1:

Per my comment (to this answer) about false negatives, a UDF or subroutine in VBA would be more appropriate, considering Match() returns the first row that has a match.

As this is not a VBA tagged post, this is a bit above the expected answer... My recommendation would be to:

  • A) Ensure you are comfortable using VBA.

  • B) Make a post about creating a user-defined function (note that any post on here about VBA has an expectation that the poster can interact with an expert on the topic and will be putting forth effort to write the code themselves, as StackOverflow is not a code-for-you service).

To help give a lead on what may be in your UDF:

  • A loop to go through the values from first row to last row in the search column (i.e., L, M, & P)

  • A variable to dynamically identify the last row of your search column

  • An if-statement to compare values from your lookup values (i.e., A2, G2, H2) to the search values at the current iteration of the loop

  • An output of 1 (has match) or 0 (no match).

There are many ways to go about this with VBA; hopefully that's a good start for you, Irina!

3 Comments

@Irina Note that this can give false negatives! If A2/G2/H2 have multiple matches, they can fail due to Match() returning the FIRST instance of a match. If you want a more fool-proof plan, VBA would be appropriate so you can loop and output a value. This could be done as a UDF (user-defined function) or a subroutine to output the desired value.
Cyril, you are right, it return even 0 - if 2 out of three values matches. can you please advise how I can you this UDF?
@Irina I just posted my recommendation for the UDF in my answer. This will take your comfort in using VBA as well as making another post specific to your UDF. Sorry that a simple excel formula doesn't appear to fit your desire ='/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.