# How to compare alternate columns dynamically

#### sanalitics

##### New Member
Hello,

How do i atomate the below scenario with formula dynamically:
Here A1 is compared with A2 and A3 is compared with A4 and so on ... if all conditions matches I want the expected result to be True

 Expected Result A1 A2 A3 A4 A5 A6 TRUE​ 1​ 1​ 2​ 2​ 3​ 3​ FALSE​ 1​ 1​ 2​ 2​ 3​ 4​

Thanks,
Sanal

If you have Excel 365, this formula is one possibility.

Code:
``````=BYROW(D2:K5;LAMBDA(row;LET(v_vals;WRAPROWS(row;2);
NOT(ISNUMBER(XMATCH(FALSE;INDEX(v_vals;;1)=INDEX(v_vals;;2)))))))``````

Notice I'm on EU style, so where I have ";", you might have ",".

I was about to post and I discovered @GraH - Guido has already responded, with a very similar solution that I was about to propose.
The only tweak I'd add is to guarantee a FALSE if the range it acts upon does not have an even number of columns; that is to wrap the
Code:
``INDEX(v_vals;;1)=INDEX(v_vals;;2)``
part in an iferror:
Code:
``IFERROR(INDEX(v_vals;;1)=INDEX(v_vals;;2);FALSE)``
this makes sure that the #N/A that appears when the formula is acting upon an odd number of columns is converted to a FALSE.

See attached. Cell P2 is recommended(!):
Code:
``=PairsMatch(A2:J13)``

edit: here's another:
Code:
``=BYROW(B2:K13,LAMBDA(a,NOT(ISNUMBER(XMATCH(FALSE,IFERROR(FILTER(a,ISODD(COLUMN(a)))=FILTER(a,ISEVEN(COLUMN(a))),FALSE))))))``

#### Attachments

• Chandoo56186.xlsx
16.1 KB · Views: 5
Last edited:
The only tweak I'd add is to guarantee a FALSE if the range it acts upon does not have an even number of columns; that is to wrap the
Code:
``INDEX(v_vals;;1)=INDEX(v_vals;;2)``
part in an iferror:
Code:
``IFERROR(INDEX(v_vals;;1)=INDEX(v_vals;;2);FALSE)``
this makes sure that the #N/A that appears when the formula is acting upon an odd number of columns is converted to a FALSE.
Very nice addition by @p45cal .

From a private conversation on the topic... ;-)