Excel公式检查重复的单词

时间:2015-05-22 04:11:03

标签: excel excel-formula

我需要一个excel公式来检查行中任何列中是否有任何单词重复。我的示例行位于以','。

分隔的列之下

列号 E221,F221,G221,H221

专栏文字 Sam,John / Sam / Smith,Smith,Kyle

Sam&史密斯的名字正在重复,所以单词应以红色突出显示。

Excel文件链接: https://docs.google.com/spreadsheets/d/1D6PZWtbk_2IVEA4l1noFzKRFu0quXSTAewmL41xOnlo/edit?usp=sharing

1 个答案:

答案 0 :(得分:0)

我认为这样做(假设您的数据在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&"/"))))
)

它提取每个单元格中的每个名称,并尝试将其与所有其他单元格匹配,因为它使用的数组常量不能直接在条件格式中使用它:您必须将其放入(比如)B2:F2并根据你的条件格式,或者使用更长的公式。

这是一个数组公式,所以需要输入 Ctrl Shift Enter

enter image description here

这是一个改进的公式。以前我在当前单元格的左侧和右侧匹配单元格:此单元格匹配包括当前单元格在内的所有单元格,并减去当前单元格与其自身匹配的匹配项数: -

=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(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)
)