ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need to search a string for numbers (https://www.excelbanter.com/excel-programming/375093-need-search-string-numbers.html)

havocdragon

Need to search a string for numbers
 
Hi all! What I am trying to do sounds like it should be easy, but it is not
working for me...Here is what I am trying to do...

User pushes a button that brings up an input box, the value typed in that is
saved as 'ColumnBox'. I then Want to check ColumnBox to see if it has numbers
in it, if it does, I want to produce an error (which I can do the error part
fine), or if there is no number than continue the procedure.

Any ideas? Ive been trying combonations of InStr and Isnumeric, but nothing
works 100%

Sandy

Need to search a string for numbers
 
Try this code as an example

Sub NumericCheck()
Dim mString As String, mChar As String
Dim i As Integer
mString = InputBox("Enter in a String")
For i = 1 To Len(mString)
mChar = Mid(mString, i, 1)
If IsNumeric(mChar) Then
MsgBox "This string has numbers in it"
Exit Sub
End If
Next i
MsgBox "This string conatined no numbers"
End Sub


Sandy

havocdragon wrote:
Hi all! What I am trying to do sounds like it should be easy, but it is not
working for me...Here is what I am trying to do...

User pushes a button that brings up an input box, the value typed in that is
saved as 'ColumnBox'. I then Want to check ColumnBox to see if it has numbers
in it, if it does, I want to produce an error (which I can do the error part
fine), or if there is no number than continue the procedure.

Any ideas? Ive been trying combonations of InStr and Isnumeric, but nothing
works 100%



Jim Cone

Need to search a string for numbers
 
another way...

Sub TellMeNoLies()
Dim ColumnBox As String
ColumnBox = "23Skidoo"
If ColumnBox Like "*#*" Then
MsgBox "No numbers ", vbExclamation
Else
MsgBox "Please continue ", vbInformation
End If
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




"havocdragon"
wrote in message

Hi all! What I am trying to do sounds like it should be easy, but it is not
working for me...Here is what I am trying to do...
User pushes a button that brings up an input box, the value typed in that is
saved as 'ColumnBox'. I then Want to check ColumnBox to see if it has numbers
in it, if it does, I want to produce an error (which I can do the error part
fine), or if there is no number than continue the procedure.
Any ideas? Ive been trying combonations of InStr and Isnumeric, but nothing
works 100%

havocdragon

Need to search a string for numbers
 
lol, sandy thats almost exactly what I did after I posted this...Jim,
thanks!! that works even better...I can't beleive I didnt think of that
seeing as I format stuff as numbers in code all the time...

"Jim Cone" wrote:

another way...

Sub TellMeNoLies()
Dim ColumnBox As String
ColumnBox = "23Skidoo"
If ColumnBox Like "*#*" Then
MsgBox "No numbers ", vbExclamation
Else
MsgBox "Please continue ", vbInformation
End If
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




"havocdragon"
wrote in message

Hi all! What I am trying to do sounds like it should be easy, but it is not
working for me...Here is what I am trying to do...
User pushes a button that brings up an input box, the value typed in that is
saved as 'ColumnBox'. I then Want to check ColumnBox to see if it has numbers
in it, if it does, I want to produce an error (which I can do the error part
fine), or if there is no number than continue the procedure.
Any ideas? Ive been trying combonations of InStr and Isnumeric, but nothing
works 100%


havocdragon

Need to search a string for numbers
 
so I will go one further now, I have the code that does this but its alot
larger than I would like.

What I need it to prevent is; Numbers, Characters, things longer than 2
characters. So basically nothing more than a combination of 2
letters...else...

"havocdragon" wrote:

lol, sandy thats almost exactly what I did after I posted this...Jim,
thanks!! that works even better...I can't beleive I didnt think of that
seeing as I format stuff as numbers in code all the time...

"Jim Cone" wrote:

another way...

Sub TellMeNoLies()
Dim ColumnBox As String
ColumnBox = "23Skidoo"
If ColumnBox Like "*#*" Then
MsgBox "No numbers ", vbExclamation
Else
MsgBox "Please continue ", vbInformation
End If
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




"havocdragon"
wrote in message

Hi all! What I am trying to do sounds like it should be easy, but it is not
working for me...Here is what I am trying to do...
User pushes a button that brings up an input box, the value typed in that is
saved as 'ColumnBox'. I then Want to check ColumnBox to see if it has numbers
in it, if it does, I want to produce an error (which I can do the error part
fine), or if there is no number than continue the procedure.
Any ideas? Ive been trying combonations of InStr and Isnumeric, but nothing
works 100%



All times are GMT +1. The time now is 02:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com