Say I have the following text string in one single Excel cell:
John John John Mary Mary
I want to create a formula (so no menu functions or VBA, please) that would give me, on another cell
John Mary
How can I do this?
What I've tried so far was search the internet and SO about the issue and all I could find were solutions involving Excel's built-in duplicate removal or something involving countif
and the replacement of duplicates for ""
. I've also taken a look at the list of Excel functions, especially those from the "Text" category, but couldn't find anything interesting, that could be done on one cell.
As I wrote, it is trivial to solve with VBA. If you cannot use VBA, one method is to use helper columns.
Assume: Your string is in A1
Enter the following formulas:
Select C1 and D1 and fill down until you start getting blanks
Select E2 and fill down.
The contents of the last cell filled in column E will be your result.
If you want to have a cell which automatically returns the contents of the last cell in column E range, you can use a formula like:
Found a solution that might work if you are also the one making the list.
when you make the list if you are doing it by combining the cell above with the current line, you can check to see if the value is already in the above cell using the following code:
Assuming you'll never have more than two distinct names in a cell, this should work:
It will show
John Mary
for all of these:It will show
John
for all of these:And it will show nothing if
A1
is blank.Without a formula: Text to Columns with space as the delimiter, transpose the output, apply Remove Duplicates to each of the columns individually, then transpose the result.
The answer is here: https://www.extendoffice.com/documents/excel/2133-excel-remove-duplicate-characters-in-string.html
Put the code above in a module
Use
=remove(A2,",")
A2 contains repeated text separated by , You may change the delimiter