Home » excel » vba – How do I eliminate duplicates when using TEXTJOIN in Excel?

vba – How do I eliminate duplicates when using TEXTJOIN in Excel?

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am currently using TEXTJOIN get all interview dates for a matching name. This is working fine except there are duplicates.

This is typical output for a name with a lot of interview dates:

03/06/19, 03/06/19, 03/06/19, 03/06/19, 03/06/19, 03/06/19, 04/06/19, 04/06/19, 
04/06/19, 04/06/19, 04/06/19, 04/06/19, 04/06/19, 04/06/19, 05/06/19, 05/06/19,
05/06/19, 05/06/19, 05/06/19, 05/06/19, 06/06/19, 06/06/19, 06/06/19, 06/06/19,
06/06/19, 06/06/19, 06/06/19, 07/06/19, 07/06/19, 07/06/19, 07/06/19, 07/06/19,
07/06/19, 14/06/19, 16/06/19, 20/06/19

I need to remove the duplicates and only show unique values. I prefer to not remove them from the source data but instead modify the TEXTJOIN formula.

C22 contains the name and TableOfInterviewDates[DateOfInterview] contains all interview dates.
I am currently using this:

{=TEXTJOIN(“, “,TRUE,IF(TableOfInterviewDates[Name]=C22,TEXT(TableOfInterviewDates[DateOfInterview], “DD/MM/YY”),””))}

I have googled this problem and tried to modify the following TEXTJOIN with duplicate removal:

{=TEXTJOIN(” & “,TRUE,IF(MATCH(A1:A6,A1:A6,0)=ROW(A1:A6)-ROW(A1)+1,A1:A6,””))}

and have ended up with this:

{=TEXTJOIN(“, “,TRUE,IF(TableOfInterviewDates[Name]=C22,TEXT(IF(MATCH(TableOfInterviewDates[DateOfInterview],TableOfInterviewDates[DateOfInterview],0)=(ROW(TableOfInterviewDates[DateOfInterview])-ROW(TableOfInterviewDates[[#Headers],[DateOfInterview]])),TableOfInterviewDates[DateOfInterview]),”DD/MM/YY”),””),””)}

Getting quite confused now and getting strange output compared to the above output with simple TEXTJOIN:

FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, 16/06/19, FALSE

Currently using this but have duplicates:

{=TEXTJOIN(“, “,TRUE,IF(TableOfInterviewDates[Name]=C2,TEXT(TableOfInterviewDates[DateOfInterview], “DD/MM/YY”),””))}

This seems to be the way forward but I am not doing something right:

{=TEXTJOIN(“, “,TRUE,IF(TableOfInterviewDates[Name]=C22,TEXT(IF(MATCH(TableOfInterviewDates[DateOfInterview],TableOfInterviewDates[DateOfInterview],0)=(ROW(TableOfInterviewDates[DateOfInterview])-ROW(TableOfInterviewDates[[#Headers],[DateOfInterview]])),TableOfInterviewDates[DateOfInterview]),”DD/MM/YY”),””),””)}

How to&Answers:

Try amending your formula as follows…

=TEXTJOIN(", ",TRUE,IF(TableOfInterviewDates[Name]=C22,IF(MATCH(TableOfInterviewDates[DateOfInterview],TableOfInterviewDates[DateOfInterview],0)=(ROW(TableOfInterviewDates[DateOfInterview])-MIN(ROW(TableOfInterviewDates[DateOfInterview]))+1),TEXT(TableOfInterviewDates[DateOfInterview],"DD/MM/YY"),""),""))

…confirmed with CONTROL+SHIFT+ENTER.