简体   繁体   中英

Excel: Check if cell contains number in text string

I have a worksheet with text strings in each cell (article title). I'd like to know if a cell contains a number. For example:

'This is 3' --> TRUE
'Red balloon' --> FALSE
' It's 10 things' --> TRUE

Update : Every answer on here works. I just chose the shortest and simplest.

与XOR LX的答案类似但是2个字符更短

=COUNT(FIND({0,1,2,3,4,5,6,7,8,9},A1))>0

Here is one formula that would do it using average:

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

or you could use small:

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

Not a very rigorous description, I'm afraid.

Perhaps:

=OR(COUNT(FIND({0,1,2,3,4,5,6,7,8,9},A1)))

Regards

If you need a VBA function:

Public Function NumberInThere(r As Range)
    Dim v As String, L As Long, i As Long
    NumberInThere = False
    v = r.Text
    L = Len(v)

    For i = 1 To L
        If IsNumeric(Mid(v, i, 1)) Then
            NumberInThere = True
        End If
    Next i
End Function

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