[英]Searching comma-separated numbers within a cell
I have a column with many comma-separated numbers, eg: 我有一列包含许多逗号分隔的数字,例如:
100633,101
123,12
100633,1000
How do I search whether a particular cell contains the number 100633
? 如何搜索特定单元格是否包含数字100633
?
In response to @Jean-François Corbett correct remark and based on the following answer 回应@Jean-FrançoisCorbett正确的言论,并基于以下回答
Check whether a cell contains a substring 检查单元格是否包含子字符串
here is a formula that searches the cell A1
for the text 100633
considering only comma separated values 这是一个仅考虑逗号分隔值而在单元格A1
中搜索文本100633
的公式
=ISNUMBER(SEARCH(",100633,",","&A1&","))
It handles correctly text like 1,2,3,999100633999
它可以正确处理1,2,3,999100633999
类的1,2,3,999100633999
You can also use FIND
instead of SEARCH
function. 您也可以使用FIND
代替SEARCH
函数。 FIND
is case sensitive. FIND
区分大小写。 With SEARCH
you can use wildcard characters. 通过SEARCH
您可以使用通配符。
Assuming the first target cell is in A1, returns TRUE or FALSE: 假设第一个目标单元格在A1中,则返回TRUE或FALSE:
=ISNUMBER(SEARCH(100633,A1))
Custom values to return if true or false: 如果是true或false,则返回自定义值:
=IF(ISNUMBER(SEARCH(100633,A1)),'yes','no)
=IF(FIND("100633",E11)=1,"Number Exists","Not Exists")
The formula searches for the text and returns whether it is present in the cell or not 该公式搜索文本并返回它是否存在于单元格中
Updated: Try Using the following excel formula: 已更新:尝试使用以下excel公式:
=MID(E18,FIND("100633",E18),6)
VBA solution: VBA解决方案:
Function CommaSeparatedListContains(ByVal csv As String, ByVal v As String, _
Optional ByVal delimiter As String = ",") As Boolean
Dim i As Long
Dim splitCsv() As String
splitCsv = Split(csv, delimiter)
CommaSeparatedListContains = False
For i = LBound(splitCsv) To UBound(splitCsv)
If splitCsv(i) = v Then
CommaSeparatedListContains = True
Exit Function
End If
Next i
End Function
Example usage: 用法示例:
=CommaSeparatedListContains(A1,100633)
Use the following method... 使用以下方法...
private boolean isNumberInvolved(String column, String number_to_check){
String[] numberArray = column.split(",");
for(int i=0; i<numberArray.length; i++){
if(numberArray[i].equals(number_to_check))
return true;
}
return false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.