Determining if numbers are part of a string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a string that can contain both letters and numbers, but it may not
contain numbers. I need to check the string to determine if there are numbers
in it. Any suggestions would be greatly appreciated.

Thanks!
 
Public Function ContainsNumbers(strMyString As String) As Boolean
Dim x As Integer
ContainsNumbers = False
For x = 1 to Len(strMyString)
If IsNumeric(Mid(strMyString,x,1)) Then
ContainsNumbers = True
Exit For
End If
Next x
End Function

Evaluate your string with the above function, e.g.,

If ContainsNumbers(nameofmystring) Then
DowhateverIwanttodo
End If
 
You can use this function that except a sring and return True if there is a
number in that string and False if there is no number

Function CheckIfNumeric(Param As String)
Dim I
CheckIfNumeric = False
For I = 1 To Len(Param)
If IsNumeric(Mid(Param, I, 1)) Then
CheckIfNumeric = True
End If
Next I
End Function
 
Back
Top