Home > Blockchain >  Formula to Remove Repeated Words in a Cell in Google Sheets
Formula to Remove Repeated Words in a Cell in Google Sheets

Time:10-07

I have created a formula to join together text from different cells in Google Sheets. The problem is that every now and then some of those cells contain the same word which ends up in the joined text.

For example, instead of saying "Large Blue T-Shirt" it will say "Large Large Blue T-Shirt" or "Large Blue Blue T-Shirt", etc. [this is just an illustrative example].

I have looked, but so far I cannot find a formula to remove repeated words in a line of text. Does such a formula exist? If so, what is that formula and how would I use it?

If not, then are there other formulas that I can use to get the desired result? Again, what are those formulas and how would I use them?

Thanks.

CodePudding user response:

Here's something with a helper column B:

=index(flatten(split(filter(A1:A&"⮐",A1:A<>"")," ")))

enter image description here

=index(trim(flatten(split(trim(query(if(B1:B={B2:B;""},,B1:B),"",9^9)),"⮐"))))

enter image description here

CodePudding user response:

Although the question isn't tagged as such, maybe a script is the way to go:

function removeDups(inString) {
  var arr;
  var outString;
  arr=inString.split(" ");;
  outString= arr[0];
  for(var i=1;i<arr.length;i  )
  {
    if (arr[i]!=arr[i-1]) outString=outString " " arr[i];
  }
  return outString;
}
  • Related