if a string contains a number then return true

tech2

New Member
Joined
Mar 8, 2011
Messages
30
I would appreciate help on a formula that would return 'TRUE' if the string contains a number. Example below. Using Excel 2007.

One Part Order 123456 for shortage items shipping to US/TX-USA

Thanks,

tech2
 
try the function below in a code module

in a cell as = HasNumber(B4) etc

Code:
Function HasNumber(w$) As Boolean
    Dim p%
    While Not HasNumber And p < Len(w)
        p = p + 1
        If Mid(w, p, 1) >= "0" And Mid(w, p, 1) <= "9" Then HasNumber = True
    Wend
End Function
 
Upvote 0
Try
=IF(SUMPRODUCT(LEN(SUBSTITUTE(A2,{1,2,3,4,5,6,7,8,9,0},"")))<>10*LEN(A2), "contains numeral", "no numerals")
 
Upvote 0
This formula will return TRUE if the text contains a number and FALSE if not...

=MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))<=LEN(A1)
 
Upvote 0
I would appreciate help on a formula that would return 'TRUE' if the string contains a number. Example below. Using Excel 2007.

One Part Order 123456 for shortage items shipping to US/TX-USA

Thanks,

tech2
Here's another one...

=COUNT(FIND({0,1,2,3,4,5,6,7,8,9},A1))>0
 
Upvote 0
Thanks for the great formula - however, I was dismayed when Excel informed me that I could not use arrays in a conditional formatting/data validation statement. HOWEVER, I wanted to post how I successfully got around that: :-) :-)

I wanted to make sure that A1 had at least 4 numbers. E.g. A98765, BC01234, etc.

In a column that would be hidden, say P, I placed this formula in cell P1:
=IF(COUNT(FIND({0,1,2,3,4,5,6,7,8,9},A1))>4,TRUE,FALSE)

Then in some other cell, say P2, I placed the formula:
=P1

For my data validation, I selected Custom --> Formula, and placed this formula:
=P2=TRUE

I hope someone finds this tidbit and it saves him/her some time. :-)
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top