2

Screenshot of example

So I want to be able to check if 2 columns have the same values, even if they're not necessarily in the same order. In the screenshot above for example, I want a formula that will return TRUE when checking if Col1 and Col5 have the same values, or Col5 and Col7, or Col1 and Col7, etc. (and FALSE otherwise). Would prefer formulas as opposed to VBA, but will use VBA if I have to.

I previously tried doing =AND(EXACT(range1,range2)), but that only works if the values in both columns are exactly in the same order.Solution attempt

BigBen
  • 46,229
  • 7
  • 24
  • 40

3 Answers3

3

Using SORT and AND:

=AND(SORT(G2:G4)=SORT(K2:K4))

enter image description here

BigBen
  • 46,229
  • 7
  • 24
  • 40
1

Not really how you asked it, but I think this may be more useful then just knowing if there's duplicates:

=LET(a, $G$1:$M$4,
     b, SEQUENCE(COLUMNS(a)),
     c, TAKE(a,1),
     d, DROP(a,1),
     HSTACK( TOCOL(c),
             MAP(TOCOL(c),
          LAMBDA(e,
                 TEXTJOIN(", ",
                          1,
                          MAP(FILTER(b,b<>XMATCH(e,c)),
                       LAMBDA(x,
                              LET(y,INDEX(d,,XMATCH(e,c)),
                              IF(
                                 AND(EXACT(SORT(y), 
                                 SORT(INDEX(d,,x)))),                                
                                 INDEX(c,,x),
                                 )))))))))

enter image description here

This takes all column headers and returns the headers (comma-separated) that exactly match (case-sensitive) regardless the order of the data in the columns.

It iterates through the columns and spills the results for all columns as shown in the screenshot.

P.b
  • 8,293
  • 2
  • 10
  • 25
  • 1
    Including text above columns; `=LET(a,$G$1:$M$4,b,SEQUENCE(COLUMNS(a)),c,TAKE(a,1),d,DROP(a,1),HSTACK(VSTACK("Column",TOCOL(c)),VSTACK("Matching column",MAP(TOCOL(c),LAMBDA(e,TEXTJOIN(", ",1,MAP(FILTER(b,b<>XMATCH(e,c)),LAMBDA(x,LET(y,INDEX(d,,XMATCH(e,c)),IF(AND(EXACT(SORT(y),SORT(INDEX(d,,x)))),INDEX(c,,x),))))))))))` – P.b Jun 23 '23 at 14:50
0

enter image description here

An array formula (CTRL + SHIFT + ENTER)

=IFERROR(AND(SUM(MATCH($F$1:$F$5 & " ";$G$1:$G$5 & " ";0))>0;
             SUM(MATCH($G$1:$G$5 & " ";$F$1:$F$5 & " ";0))>0);FALSE)