简体   繁体   中英

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 ?

In response to @Jean-François Corbett correct remark and based on the following answer

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

=ISNUMBER(SEARCH(",100633,",","&A1&","))

It handles correctly text like 1,2,3,999100633999

You can also use FIND instead of SEARCH function. FIND is case sensitive. With SEARCH you can use wildcard characters.

Assuming the first target cell is in A1, returns TRUE or FALSE:

=ISNUMBER(SEARCH(100633,A1))

Custom values to return if true or 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:

=MID(E18,FIND("100633",E18),6)

VBA solution:

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;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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