1

I have a column with many comma-separated numbers, e.g.:

   100633,101

    123,12

   100633,1000

How do I search whether a particular cell contains the number 100633?

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
Myra
  • 77
  • 1
  • 2
  • 9

5 Answers5

2

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.

Community
  • 1
  • 1
Vojtěch Dohnal
  • 7,867
  • 3
  • 43
  • 105
  • Doesn't this answer only work if "100633" is NOT FIRST in the comma-delimited list? IE, the search is for a number that STARTS WITH and ends with a comma. If it's the first number in the list, it won't start with a comma, and so will not be found? – Tom Auger Nov 04 '15 at 16:58
  • 1
    @TomAuger No, since it searches within `","&A1&","` and not within just A1. – Vojtěch Dohnal Nov 05 '15 at 07:21
0

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)
chishaku
  • 4,577
  • 3
  • 25
  • 33
0
=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)

sabhareesh
  • 324
  • 1
  • 4
0

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)

enter image description here

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
-1

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;
    }
Zin Win Htet
  • 2,448
  • 4
  • 32
  • 54
  • 1
    Thanks everyone ..That time I needed the solution quickly so used a very raw method...Now ,I am applying these methods. There are many correct answers for this apart for the one I checked (as answer). Bt I am not able to select all. So selected the one whose formulae I am applying . Thanks a lot again. – Myra Sep 12 '14 at 04:37