Compare Two Columns in Two Sheets to Remove Duplicates and Return One Copy Only

%3CLINGO-SUB%20id%3D%22lingo-sub-2695240%22%20slang%3D%22en-US%22%3ECompare%20Two%20Columns%20in%20Two%20Sheets%20to%20Remove%20Duplicates%20and%20Return%20One%20Copy%20Only%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2695240%22%20slang%3D%22en-US%22%3EGood%20Day%2C%20Friends!%3CBR%20%2F%3E%3CBR%20%2F%3EI%20have%20one%20column%20in%20sheet1%20and%20the%20other%20in%20sheet2.%3CBR%20%2F%3E%3CBR%20%2F%3EColumns%20have%20duplicates%2C%20within%20itself%20as%20a%20column%2C%20as%20well%20as%20when%20both%20columns%20are%20compared%20to%20each%20other.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20would%20like%20to%20request%20to%20have%20one%20master%20column%20in%20sheet3%20that%20would%20find%20and%20remove%20duplicates%20but%20keep%20one%20of%20its%20originals%20and%20return%20the%20text%20into%20the%20master%20column%20in%20sheet3.%3CBR%20%2F%3E%3CBR%20%2F%3EAlso%2C%20this%20master%20column%20should%20update%20and%20sort%20whenever%20any%20new%20names%20are%20added%20into%20either%20of%20those%20columns%20in%20sheet1%20or%20sheet2.%3CBR%20%2F%3E%3CBR%20%2F%3EPlease%20note%2C%20I%20would%20especially%20like%20to%20have%20an%20automated%20column%20in%20sheet3%2C%20this%20means%2C%20I%20would%20like%20to%20request%20for%20an%20non-cse%20(control-shift-enter)%20array%20column.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20have%20attached%20the%20excel%20file%20for%20your%20review.%3CBR%20%2F%3E%3CBR%20%2F%3EThank%20you%20very%20much%20in%20advance%20for%20helping%20out%2C%20really!%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2695240%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2695259%22%20slang%3D%22en-US%22%3ERe%3A%20Compare%20Two%20Columns%20in%20Two%20Sheets%20to%20Remove%20Duplicates%20and%20Return%20One%20Copy%20Only%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2695259%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1140142%22%20target%3D%22_blank%22%3E%40major_johnson%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20variant%20that%20could%20be%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3DLET(%0A%20%20ra%2C%20ROWS(Table1)%2C%0A%20%20rb%2C%20ROWS(Table2)%2C%0A%20%20k%2C%20SEQUENCE(ra%2Brb)%2C%0A%20%20SORT(%20UNIQUE(%20IF(k%26lt%3B%3Dra%2C%20INDEX(Table1%5BColumn1%5D%2C%20k)%2C%20INDEX(Table2%5BColumn2%5D%2C%20k-ra))))%0A)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Ewhich%20returns%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20226px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F306419i0EFB9B08F0FC4F0A%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2695311%22%20slang%3D%22en-US%22%3ERe%3A%20Compare%20Two%20Columns%20in%20Two%20Sheets%20to%20Remove%20Duplicates%20and%20Return%20One%20Copy%20Only%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2695311%22%20slang%3D%22en-US%22%3EThank%20you%20very%20much%20for%20your%20reply.%3CBR%20%2F%3E%3CBR%20%2F%3EAnd%20although%20the%20what%20needed%20is%20100%25%20correct%20but%20I%20would%20really%20appreciate%20a%20formula%20instead%20of%20an%20array%20that%20is%20dragged%20down%20to%20a%20certain%20point%20and%20those%20cells%20are%20updated%20as%20accordingly.%3CBR%20%2F%3E%3CBR%20%2F%3EA%20formula%20that%20engages%20in%20a%20mixture%20of%20index%20and%20match%20is%20especially%20not%20control-shift-enter.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20hope%20you%20understand.%3CBR%20%2F%3E%3CBR%20%2F%3EThank%20you%20again%20for%20you%20help%2C%20I%20really%20do%20appreciate%20it!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2695316%22%20slang%3D%22en-US%22%3ERe%3A%20Compare%20Two%20Columns%20in%20Two%20Sheets%20to%20Remove%20Duplicates%20and%20Return%20One%20Copy%20Only%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2695316%22%20slang%3D%22en-US%22%3EAlso%2C%20after%20double%20checking%2C%20the%20master%20column%20in%20sheet3%20does%20not%20update%20or%20correspond%20whenever%20I%20add%20or%20amend%20items.%3CBR%20%2F%3E%3CBR%20%2F%3EAgain%2C%20please%2C%20I%20need%20a%20formula.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2695338%22%20slang%3D%22en-US%22%3ERe%3A%20Compare%20Two%20Columns%20in%20Two%20Sheets%20to%20Remove%20Duplicates%20and%20Return%20One%20Copy%20Only%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2695338%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1140142%22%20target%3D%22_blank%22%3E%40major_johnson%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat%20is%20not%20CSE%20formula%2C%20that%20is%20regular%20formula%20which%20returns%20the%20spill%20automatically%20updated%20if%20you%20add%20new%20data%20into%20structured%20tables%20(Table1%20and%20Table2).%20If%20I%20add%20some%20data%20into%20Table1%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20230px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F306430iB734B1082AAE65E0%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3Eand%20same%20into%20Table2%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20234px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F306431i90171025AB77C299%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3Eresulting%20spill%20will%20be%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20233px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F306432i4DB5B3F4A345AF64%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2695340%22%20slang%3D%22en-US%22%3ERe%3A%20Compare%20Two%20Columns%20in%20Two%20Sheets%20to%20Remove%20Duplicates%20and%20Return%20One%20Copy%20Only%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2695340%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20see%20the%20attached%20file.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor
Good Day, Friends!

I have one column in sheet1 and the other in sheet2.

Columns have duplicates, within itself as a column, as well as when both columns are compared to each other.

I would like to request to have one master column in sheet3 that would find and remove duplicates but keep one of its originals and return the text into the master column in sheet3.

Also, this master column should update and sort whenever any new names are added into either of those columns in sheet1 or sheet2.

Please note, I would especially like to have an automated column in sheet3, this means, I would like to request for an non-cse (control-shift-enter) array column.

I have attached the excel file for your review.

Thank you very much in advance for helping out, really!
10 Replies

@major_johnson 

As variant that could be

=LET(
  ra, ROWS(Table1),
  rb, ROWS(Table2),
  k, SEQUENCE(ra+rb),
  SORT( UNIQUE( IF(k<=ra, INDEX(Table1[Column1], k), INDEX(Table2[Column2], k-ra))))
)

which returns

image.png

Thank you very much for your reply.

And although the what needed is 100% correct but I would really appreciate a formula instead of an array that is dragged down to a certain point and those cells are updated as accordingly.

A formula that engages in a mixture of index and match is especially not control-shift-enter.

I hope you understand.

Thank you again for you help, I really do appreciate it!
Also, after double checking, the master column in sheet3 does not update or correspond whenever I add or amend items.

Again, please, I need a formula.

@major_johnson 

That is not CSE formula, that is regular formula which returns the spill automatically updated if you add new data into structured tables (Table1 and Table2). If I add some data into Table1

image.png

and same into Table2

image.png

resulting spill will be

image.png

@Sergei Baklan 

 

Please see the attached file.

Oh, I am sorry, I am using MS Pro. Plus 2010.

@major_johnson 

@Sergei Baklan's solution is perfect for your needs, as one might expect.  I redid the solution from scratch and there are barely any differences

 

= LET(
    n₁, ROWS(Column1),
    n₂, ROWS(Column2),
    k, SEQUENCE(n₁+n₂),
    vstack, IF(k<=n₁, Column1, INDEX(Column2, k-n₁)),
    SORT(UNIQUE(vstack))
  )​

 If you are using anything but Excel 365, get rid of it and replace it by 365.  If you are using 365, make sure that you allow the formula to spill and do not use CSE.

This is all great stuff, but guys, I want to do it on 2010 and with a formula.

And yes, I do have 365 but on my personal laptop.

This is for work and they are still using 2010.

@major_johnson 

This takes me back to stuff I was thankful to see the back of, hopefully forever!

First, defining  n₁, n₂ and 'combined'

= ROWS(Table1)
= ROWS(Table2)

= IF(k<=n₁, 
    Column1, 
    IF(k<=n₁+n₂, 
      INDEX(Column2, k-n₁),
      ""
    )
  )

one the uses MATCH to identify the first occurrence and SMALL to compact the list

= IFERROR(
    INDEX(
      combined,
      SMALL(
        IF( MATCH(combined, combined, 0) = k, k, "" ),
        @k
      )
    ),
 "" )

I have also shown a PowerQuery solution that works with Office 2010 but requires an additional software download.

let
    Source = Table.Combine({Table1, Table2}),
    Distinct = Table.Distinct(Source),
    Text = Table.TransformColumnTypes(Distinct,{{"Data", type text}})
in
    Text

All of which serves to reinforce my dislike of conventional spreadsheets!