Excel formula to check for duplicate words - excel

I require an excel formula to check if any words are being duplicated in any column in a row. My sample row is below columns separated by a ','.
Column No: E221, F221, G221, H221
Column Text: Sam, John/Sam/Smith, Smith, Kyle
Above Sam & Smith names are being repeated so the words should be highlighted in red.
Excel File Link:
https://docs.google.com/spreadsheets/d/1D6PZWtbk_2IVEA4l1noFzKRFu0quXSTAewmL41xOnlo/edit?usp=sharing

I think this does the job (assuming you have your data in B1:F1):-
=if(b1="",0,
SUM(1-(ISERROR(FIND(MID("/"&B1&"/",FIND("|",SUBSTITUTE("/"&B1&"/","/","|",{1;2;3;4;5;6})),FIND("|",SUBSTITUTE("/"&B1&"/","/","|",{2;3;4;5;6;7}))-FIND("|",SUBSTITUTE("/"&B1&"/","/","|",{1;2;3;4;5;6}))+1),"/"&$A$1:A$1&"/"))))
+SUM(1-(ISERROR(FIND(MID("/"&B1&"/",FIND("|",SUBSTITUTE("/"&B1&"/","/","|",{1;2;3;4;5;6})),FIND("|",SUBSTITUTE("/"&B1&"/","/","|",{2;3;4;5;6;7}))-FIND("|",SUBSTITUTE("/"&B1&"/","/","|",{1;2;3;4;5;6}))+1),"/"&C$1:$G$1&"/"))))
)
It extracts each name in each cell and tries to match it with all other cells but because it uses array constants you can't use it directly in conditional formatting: you would have to put this in (say) B2:F2 and base your conditional formatting on it, or else use an even longer formula.
It's an array formula, so need to enter it with Ctrl Shift Enter
Here is an improved formula. Previously I was matching cells to the left and right of the current cell: this one matches all cells including the current cell and subtracts the number of matches where the current cell matches with itself:-
=if(b1="",0,
SUM(1-(ISERROR(FIND(MID("/"&B1&"/",FIND("|",SUBSTITUTE("/"&B1&"/","/","|",{1;2;3;4;5;6})),FIND("|",SUBSTITUTE("/"&B1&"/","/","|",{2;3;4;5;6;7}))-FIND("|",SUBSTITUTE("/"&B1&"/","/","|",{1;2;3;4;5;6}))+1),"/"&$B$1:$F$1&"/"))))
-(LEN(B1)-LEN(SUBSTITUTE(B1,"/",""))+1)
)
If you wanted a formula that you could use directly in conditional formatting, I think you would have to enumerate all possible matches for all possible substrings separately which is rather tedious:-
=if(b1="",0,
SUM(
1-(ISERROR(FIND(MID("/"&B1&"/",FIND("|",SUBSTITUTE("/"&B1&"/","/","|",1)),FIND("|",SUBSTITUTE("/"&B1&"/","/","|",2))-FIND("|",SUBSTITUTE("/"&B1&"/","/","|",1))+1),"/"&$B$1:$F$1&"/"))),
1-(ISERROR(FIND(MID("/"&B1&"/",FIND("|",SUBSTITUTE("/"&B1&"/","/","|",2)),FIND("|",SUBSTITUTE("/"&B1&"/","/","|",3))-FIND("|",SUBSTITUTE("/"&B1&"/","/","|",2))+1),"/"&$B$1:$F$1&"/"))),
1-(ISERROR(FIND(MID("/"&B1&"/",FIND("|",SUBSTITUTE("/"&B1&"/","/","|",3)),FIND("|",SUBSTITUTE("/"&B1&"/","/","|",4))-FIND("|",SUBSTITUTE("/"&B1&"/","/","|",3))+1),"/"&$B$1:$F$1&"/"))),
1-(ISERROR(FIND(MID("/"&B1&"/",FIND("|",SUBSTITUTE("/"&B1&"/","/","|",4)),FIND("|",SUBSTITUTE("/"&B1&"/","/","|",5))-FIND("|",SUBSTITUTE("/"&B1&"/","/","|",4))+1),"/"&$B$1:$F$1&"/"))),
1-(ISERROR(FIND(MID("/"&B1&"/",FIND("|",SUBSTITUTE("/"&B1&"/","/","|",5)),FIND("|",SUBSTITUTE("/"&B1&"/","/","|",6))-FIND("|",SUBSTITUTE("/"&B1&"/","/","|",5))+1),"/"&$B$1:$F$1&"/"))),
1-(ISERROR(FIND(MID("/"&B1&"/",FIND("|",SUBSTITUTE("/"&B1&"/","/","|",6)),FIND("|",SUBSTITUTE("/"&B1&"/","/","|",7))-FIND("|",SUBSTITUTE("/"&B1&"/","/","|",6))+1),"/"&$B$1:$F$1&"/"))))
-(LEN(B1)-LEN(SUBSTITUTE(B1,"/",""))+1)
)

Related

Splitting names given in single cells without using text to column excel

i want to use excel formula to split multiple names given in a single cell. dont want to use text to column feature. For example
in the above yellow is the variable name & the green color is the required format
See find the nth instance of a character: FIND(CHAR(1),SUBSTITUTE(string,delimiter,CHAR(1),nth)). For the first, we use LEFT(string,position_first-1). For the last: RIGHT(string,LEN(string)-position_last). For all in between: MID(string,position_first+1,position_second-position_first-1).
So, combining the logic, we may get this:
=IFERROR(IFERROR(IF(B$1=1,LEFT($A2,FIND(CHAR(1),SUBSTITUTE($A2,"/",CHAR(1),1),1)-1),MID($A2,FIND(CHAR(160),SUBSTITUTE($A2,"/",CHAR(160),B$1-1),1)+1,FIND(CHAR(1),SUBSTITUTE($A2,"/",CHAR(1),1+B$1-1),1)-FIND(CHAR(1),SUBSTITUTE($A2,"/",CHAR(1),B$1-1),1)-1)),RIGHT($A2,LEN($A2)-FIND(CHAR(1),SUBSTITUTE($A2,"/",CHAR(1),B$1-1),1))),"")
IFERROR(...,"") is used to return "" after last occurrence (below, in G2). Nested IFERROR(... RIGHT) will be triggered at last occurrence (since MID will fail there; below at F2).
Try using this:
With the full name in cell A2, the formulas go as follows:
Get the first name:
=LEFT(A2,SEARCH(" ",A2)-1)
Get the last name:
=RIGHT(A2,LEN(A2)-SEARCH(" ",A2,1))
You enter the formulas in cells B2 and C2, respectively, and drag the fill handle to copy the formulas down the columns. The result will look something similar to this:

Is there an excel formula that can check the number of words in consecutive cells and give an output based on conditions?

I am trying to create an output in excel based off the number of words in cells. Essentially i want to check if the sum of the words in 3 cells is = 1,2 or >=3. Im using the len formula which i have successfully used on single cell conditions but im struggling to create the formula that would check multiple cells.
Below is an example of my data:
Column A Column B Column C
Cat;dog Bird
Formula
=SUMIF(AND(LEN(TRIM(A4))-LEN(SUBSTITUTE(B4," ",""))+1, LEN(TRIM(C4))-LEN(SUBSTITUTE(C4," ",""))+1, >=3), "Titanium")
https://docs.google.com/spreadsheets/d/1W6nFr-W0r-XWZnvrFWndsvdBEEGHMQUa/edit?usp=sharing&ouid=103068518904190156690&rtpof=true&sd=true
First I made a single formula to work on a single cell. It ignores semicolons and commas to calculate total words. That formula is in column F and it's:
=IF(LEN(E5)=0;0;LEN(TRIM(SUBSTITUTE(SUBSTITUTE(E5;";";" ");",";" ")))-LEN(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(E5;";";" ");",";" "));" ";""))+1
Notice I added an IF to make sure that blank cells will count as 0 words (because the +1 will be added wrongly and we need to avoid this.
Now you just need to sum up all results and we get 8 words.
What you want is to get this result with a single formula and that can be perfomed with array formulas. In cell F11 my formula is:
=SUM(IF(LEN(E5:E8)=0;0;LEN(TRIM(SUBSTITUTE(SUBSTITUTE(E5:E8;";";" ");",";" ")))-LEN(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(E5:E8;";";" ");",";" "));" ";""))+1))
You need to introduce this formula pressing CTRL+ENTER+SHIFT or it won't work!
Now you got the result in a single formula and you just need to add your conditions mentioned in your post
UPDATE: In your Google Sheets, the correct formula would be:
=ArrayFormula(IF(SUM(IF(LEN(TRIM(A3:B3))=0,0,LEN(TRIM(A3:C3))-LEN(SUBSTITUTE(A3:C3," ",""))+1))>=3,"Good","Bad"))
Please, notice Excel is not the same as Google Sheets so sometimes the formulas may be different in one of them.

=ISNUMBER(SEARCH()) formula not working properly

Basically, im trying to search if values from column b is contained in cells on column a
I am currently using the formula
=ISNUMBER(SEARCH(B1,$A:$A))
and using it inside a conditional formatting to highlight the cells in column A that contains strings from column B. But it is not highlighting the correct cells
any advice?
Problem is that your ISNUMBER(SEARCH(…. formula is returning an array of values {FALSE;TRUE;FALSE;FALSE;...} one return for each item in within_text. You need to know if any of those items match.
So, with your formula, consider the array formula modification
=OR(ISNUMBER(SEARCH(B1,$A:$A)))
Since this is an array formula, you need to "confirm" it by holding down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula as observed in the formula bar
If you don't like to use the CSE entry method, you could use this formula which will return zero for no matches, or be non-zero for any matches:
=SUMPRODUCT(-ISNUMBER(SEARCH(B1,$A:$A)))
Excel's SEARCH function is used to find the position of one string within another string. Generally you use it like this:
=SEARCH("String A", "A Longer String Containing String A")
This will return the character index where first string starts within the second string, which in this case would be 28.
What you really need is a VLOOKUP. Since you're doing a textual search (substring), you need your range to be of text type instead of number.
You should do the following:
Add an extra column to the right of Column A and use TEXT function to convert entries to textual form:
=TEXT(A1, "#")
Now you can use VLOOKUP to perform a substring-match in this textual range. VLOOKUP supports wildcards when you do not ask it to perform an exact match (4th argument should be FALSE). Here is your formula then:
=VLOOKUP("*" & C1 & "*",$B:$B,1,FALSE)
Note that I have passed column B (textual column) as the lookup range, whereas C1 is the cell containing the text that you want to search.
This method also has the additional advantage that it returns the actual matched entry from the range so you don't have to find it manually.
Once you have your results, you can apply conditional formatting to it.
Highlight column A (or the relevant range in column A starting cell A1) with the first cell (which is A1 in this case) as the active cell, use the following formula as the conditional formatting rule:
=(SEARCH($B1,$A1)*(LEN($B1)>0))>0
The logic is to first search the given sub-string from the main string, then multiple the result by LEN($B1)>0 to exclude the result of 1 returned for blank cells in column B.
Note: Conditional Formatting works in array fashion so even though the formula only looks at values in the first row of the range, as long as you use the relative (or in some cases absolute) cell references correctly and highlight the result range correctly before setting up the rule, the rule will be applied across in the same way as for the first row of the array as demonstrated in this example.

How to highlight cell that does not contain specific text from any column

I have a excel file with 2 excel sheet. The sheets are called first and second.
For the first sheet, it contain 1 column, animal while the other sheet, it contains 1 columns, sentence.
name of the 1st sheet: first
animal
cat
fly
deer
dog
deer
snail
name of the 2nd sheet: second
sentence
thedogpoops
thedeerismyinhouse
where is my cat
theflyis annoying
In the first sheet, if any of the animal is not contained in the second sheet, it should be highlighted. "snail" should be highlighted in animal sheet
I used search excel formula to do this. I go to conditional formatting and use a formula to determine which cells to format. I implemented the code
=NOT(ISNUMBER(SEARCH('Sheet 1'!$A:$A,$A:$A)))
The output is that the whole animals is highlighted
What I am trying to do is that if the animal is not found in any of the column, it will be highlighted. However it does not work. Can you please correct this problem?
Based on your example this should work:
=if(A3="","",if(count(search(A3,second!$A:$A))>0,":-)",":-("))
ARRAY FORMULA press SHIFT + CTRL + ENTER to enter formula
You can place that beside the animal and pull it down.
You can use conditional formatting on the list to highlight like in my case ":-(" the sad smiley or you use better visible letters for highlighting.
If you just want to highlight the "missing" animals, then delete the happy smiley from the formula.
=if(A3="","",if(count(search(A3,second!$A:$A))>0,"",":-("))
ARRAY FORMULA press SHIFT + CTRL + ENTER to enter formula
Select column A on the Animals worksheet and create a CFR based on this formula,
=isna(match("*"&$A1&"*", 'Sheet 2'!$A:$A, 0))
By 'wildcarding' the match to the value in the 'Animals' worksheet you are creating a 'contains within' criteria to any string in Sheet 2's column A like the non-case-sensitive SEARCH function.
Rather than produce a series of images on how to do it manualy, this is the VBA equivalent.
With worksheets("Animals").range("a:a")
.FormatConditions.Delete
with .FormatConditions.Add(Type:=xlExpression, Formula1:="=isna(match(char(42)&$A1&char(42), 'Sheet 2'!$A:$A, 0))")
.Interior.Color = vbred
end with
End With
When a cell contains an error like #VALUE! this is not text with those the phrase "VALUE"; not something you can (or should) search for in this way. It is a sort of placeholder showing where an error is.
To determine whether a formula or function results in an error use ISERROR or IFERROR.
For example, if you want to return Not Found if your formula produces an error, you could use:
=IFERROR(SEARCH($A:$A,'Sheet 2'!$A:$A),"Not Found")
I prefer VLOOKUP for finding matches.
For example, you could enter in cell B2 on sheet First:
=VLOOKUP("*" &A2&"*",second!$A$2:$A$5,1,FALSE)
...and then fill or copy the formula down to cell A7.
If a matching phrase is found in Second then it will show that phrase, otherwise it will produce an error.
This time using ISERROR (as well an IF) as an example, you could display whether or not there was a match by instead using this formula in cell B2 on sheet First:
=IF(ISERROR(VLOOKUP("*"&A2&"*",second!$A$2:$A$5,1,FALSE)),"No Match","Matched!")
...and then fill or copy the formula down to cell A7.
More Information:
TechOnTheNet : How to use the ISERROR Function
ExcelJet : How to use the Excel IFERROR Function

How to add white spaces in a field of Excel which is equal to length of a longer word

I have a scenario where I want my Microsoft excel field to have the same length of the longest word in the column.
Basically lets say if I have:
ACBBASDBBADSAD
BADFDFDDF
So here I want to have the second word with less characters to have white spaces at its end to match the length of the first word.
=&" " this definitely helps but I am unable to achieve the above scenario
Consider this screenshot:
In column B the length of each cell of column A is established with the formula =len(A1) copied down.
Cell D2 has the range name MaximumLength and the formula =max(B:B).
With that in place, you can create the padded values with this formula in cell G1, copied down:
=A1&REPT("*",MaximumLength-LEN(A1))
If you don't want to use the helper column and helper cell, you can use this array formula instead:
=A2&REPT("*",MAX(LEN(A1:A15))-LEN(A2))
This formula must be confirmed with Ctrl-Shift-Enter. It is advisable to use defined ranges, not whole columns in array formulas, hence the range in LEN(A1:A15). Adjust as desired.
I've used the "*" character so it is visible. Replace it with a space " " in your scenario.
You can add this formula to count maximum characters and use on some cell, because you will need to press a command for it to work, so every cell can't contain this formula, let's say it is on Z1:
=MAX(LEN($A:$A))
Certify to press ctrl+shift+enter on the formula
Then you use this formula on your cells:=REPT(" ";Z1-LEN(A2))&A2
Edit: Sorry, anwsered late, teylyn is more complete.

Resources