简体   繁体   English

Excel:如何检查单元格内的重复数字

[英]Excel: How to check for repeated numbers inside a cell

I have an excel spreadsheet with numbers from 000 to 999 and am trying to find repeated numbers inside a cell. 我有一个Excel电子表格,其数字从000到999,并且试图单元格中查找重复的数字。

(So for example, printing 1 if the number is 022 , 555 or 115 and 0 if it isn't) (因此,例如,打印1如果数字为022,555115和0,如果它不是)

So far, I have not been able to find a solution. 到目前为止,我还没有找到解决方案。

Feel free to ask for more information and thanks in advance. 随时询问更多信息,并提前致谢。

This will do: =IF(COUNT(SEARCH(REPT({0,1,2,3,4,5,6,7,8,9},2),A1))>0,1,0) 这将做到: =IF(COUNT(SEARCH(REPT({0,1,2,3,4,5,6,7,8,9},2),A1))>0,1,0)

Note: If value in cell A1 contains 2 repeated digits it will show 1 else 0. You can customize the repetition limit by changing 2 in the part 8,9}, 2 ) . 注意:如果单元格A1中的值包含2个重复数字,则将显示1否则为0。您可以通过在部分8,9}, 2 )中更改2来定制重复限制。

You could try this one if you wanted to find repeated digits not necessarily next to each other:- 如果您想查找不一定彼此相邻的重复数字,可以尝试使用此数字。

=IF(MAX(LEN(A1)-LEN(SUBSTITUTE(A1,{0,1,2,3,4,5,6,7,8,9},"")))>1,1,0)

If the numbers are stored as 3-digit numbers and you wanted it to work for (eg) 001, would need:- 如果数字存储为3位数字,并且您希望它适用于(例如001),则需要:-

=IF(MAX(LEN(TEXT($A1,"000"))-LEN(SUBSTITUTE(TEXT($A1,"000"),{0,1,2,3,4,5,6,7,8,9},"")))>1,1,0)

在此处输入图片说明

If your data is in Range "A1:A100" and you want to locate repeated numbers in the range for instance, enter =IF(COUNTIF(A:A,A1)>1,1,0) in cell B1 and fill down. 如果您的数据在“ A1:A100”范围内,并且您想在该范围内找到重复的数字,请在单元格B1中输入= IF(COUNTIF(A:A,A1)> 1,1,0)并填写。 But if you want to check repetitions of specific numbers like 022, 555 or 115, enter =IF(OR(AND(A1=022,COUNTIF(A:A,A1)>1),AND(A1=555,COUNTIF(A:A,A1)>1),AND(A1=115,COUNTIF(A:A,A1)>1)),1,0) in cell B1 and fill down. 但是,如果您要检查特定数字的重复次数,例如022、555或115,请输入= IF(OR(AND(A1 = 022,COUNTIF(A:A,A1)> 1),AND(A1 = 555,COUNTIF(A :A,A1)> 1),AND(A1 = 115,COUNTIF(A:A,A1)> 1)),1,0)在单元格B1中填写。

being a number, use arithmetics to break it into digits and then check if all are different. 是一个数字,请使用算术将其分解为数字,然后检查所有数字是否都不同。

the formula is 公式是

=INT(NOT(AND(INT(A1/100)<>INT(MOD(A1,100)/10),INT(A1/100)<>MOD(A1,10),INT(MOD(A1,100)/10)<>MOD(A1,10))))

let's analyze it step by step 让我们逐步分析它

first, INT(A1/100) extracts the first digit (the integer division by 100); 首先, INT(A1/100)提取第一个数字(整数除以100); then INT(MOD(A1,100)/10) extracts the second digit (the integer division by 10 of the modulo 100); 然后INT(MOD(A1,100)/10)提取第二个数字(以100为模的整数除以10); and MOD(A1,10) extracts the last digit (the modulo 10). MOD(A1,10)提取最后一位数字(模10)。

next there are the three comparisons of difference <> first with second, second with third and first with third, combined with AND() and finally take the result, negate it NOT() and transforming it into an integer 0 or 1 with INT() 接下来是差值<>的三个比较,第一个与第二个比较,第二个与第三个比较,第一个与第三个比较,与AND()合并,最后得到结果,取反NOT()并用INT() NOT()将其转换为整数0或1 INT()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM