requesting excel formula to compare columns but going in order and skipping blanks

46 Views Asked by At

Trying to setup a formula in excel to compare 2 colums, sample data set below. Considering there will be blanks in column B and we must go in order

Column A Column B Column C
3 3 match
4 3 difference
5 blank skipped
6 5 match
6 5 difference
8 6 match
blank blank skipped
blank 8 match

Tried a few formulas but not giving the results required

=IF(B1="", "", IF(ISNUMBER(MATCH(A1, IF(B:B<>"", B:B), 0)), "Match", "Difference"))

=IF(AND(A1<>"", B1<>"", A1=B1), "Match", IF(B1="", "", "Difference"))

=IF(A1<>"", IFERROR(IF(ISBLANK(B1), IFERROR(INDEX(B:B, MATCH(FALSE, ISBLANK(B:B), 0)), ""), IF(A1=B1, "Match", "Difference")), ""), "")
2

There are 2 best solutions below

2
Scott Craner On BEST ANSWER

Use a nested if with COUNTIF

=IF(B1="","skipped",IF(COUNTIF(A:A,B1)>=COUNTIF($B$1:B1,B1),"match","difference"))

enter image description here

1
Tom Sharpe On

I had a slightly different take on this

=IF(B1="","skipped",IF(B1=INDEX(A:A,COUNT(B$1:B1)),"match","difference"))

but I realise this will break after the blanks in column A and something more would be required like an mmult.

enter image description here


This was my thinking if the pattern continues like this, to use Mmult to find the next value in column A to compare:

=IF(B1="","skipped",IF(B1=INDEX(A:A,MATCH(COUNT(B$1:B1),
MMULT(IF(COLUMN($A$1:$J$1)<=ROW($A$1:$A$10),1,0),SIGN(A$1:A$10)),0)),
"match","difference"))

enter image description here


In a further test, my result (column E) would be at variance with @Scott Craner's (Column F) because I am comparing 8 against 7 and 9 against 8:

enter image description here


I you were able to set up a helper column starting from (say) C1 which counted the number of cells in column A containing a number up to the corresponding row, then you could use a much simpler formula which would work better with larger amounts of data:

=IF(B1="","skipped",IF(B1=INDEX(A:A,MATCH(COUNT(B$1:B1),
C$1:C$10,0)),"match","difference"))