Excel Formula for Finding Repeated Words in a Cell

Posted on November 11th, 2008 in Learn Excel - 8 comments

excel-repeat-word-formula-help

If you ever need to know whether a particular word is repeated in a cell (for eg: a file extension or telephone number or name of the customer) here is how you can find it.

=if(lower(cell-with-text)<>SUBSTITUTE(lower(cell-with-text),lower(word-to-check),"",2),"Yes","No")

We are using substitute() to replace the second occurance of a particular word and then compare this with original cell contents. If both are not equal, we know that the word is repeated.

For eg: =if(lower("all cats are dogs, but not all dogs are cats")<>SUBSTITUTE(lower("all cats are dogs, but not all dogs are cats"),lower("cat"),"",2),"Yes","No") would return “yes”

See related posts for more text processing using excel hacks.

| More
Subscribe for PHD Email updates and get a free excel e-book with 95 tips & tricks

Comments
kidakaka November 11, 2008

Nice Chandoo!! So I can now do pattern matching and tracking!

Michelle November 11, 2008

Very useful!!! I had no idea it could be done… thank you!!

azmat November 11, 2008

hi chandoo,
i got this below formulae on another site which picks all the text appearing after “/” in a cell….however i can’t understand how it works….specially if you could tell me what does this REPT function and 255 value does in this formulae…..

=TRIM(RIGHT(SUBSTITUTE(B23,”/”,REPT(” “,255)),255))

u can call me a novice wrt formulaes……

Chandoo November 11, 2008

@Kida… yeah, you can do some basic pattern matching using this other text manipulation functions.

@Michelle: you are welcome :)

@Azmat: Thanks for sharing this formula with all. Even I didn’t know about this and it definitely goes in to my favorite formula tricks.

here is how it works:
- the formula produces portion of the cell contents after last “/” symbol.
- assuming, the last part is not longer than 255 characters (usually the case)
- It replaces every “/” with 255 spaces (the rept() function is doing that)
- Now, it uses right() to extract right most 255 characters. Which probably has a bunch of spaces and then the last portion and another bunch of space.
- Finally it uses trim to cut down spaces to provide just the string.

If your string has more than 255 characters after the last “/” symbol, you can use even larger number like 999 in rept() and right().

Glenn August 20, 2009

Is there a formula if I want to see if a word is repeated in a column?

Chandoo August 20, 2009

@Glenn you can try countif()

assuming you want to see if word “Glenn” is repeated in the range C1:C20, write something like =IF(COUNTIF(C1:C20,”*Glenn*”)>1,”Repeated”,”Not Repeated”)

RSS feed for comments on this post. TrackBack URI

Leave a comment

   Name (required)

   E-mail (required, never displayed)

   URL


If you have a question, please ask in the forums

Recommended Excel, Charting, VBA books