Forum Home
Press F1
 
Thread ID: 88718 2008-04-07 00:39:00 Does VBA string contain number? Mike (15) Press F1
Post ID Timestamp Content User
656638 2008-04-07 00:39:00 I'm trying to modify a vba script I wrote, and need to check whether a particular user defined string contains a number (the string is an address)

so if user types in "5 Jones Street", I'd get containsnumber = 1
and if user types in "Jones Street", I'd get containsnumber = 0

or something along those lines. The first character isn't always a number (eg "A-E/5 Jones Street") - the number can be anywhere in the string.

Can anyone point me in the right direction? I am guessing I could use something like the search and mid functions (like in Excel), but how I tell it to specifically look for a number in the string I don't really know.

This is not an Excel vba script, so using specifically Excel functions may not work.

Does all that make sense? :)

Cheers,
Mike.
Mike (15)
656639 2008-04-07 00:55:00 I've done it, although if anyone has a better/correct way to do it I'd appreciate you posting it here :)


Dim myString As String
Dim i As Integer
Dim myOtherString As String
myString = "A-J 5 Jones Street"
For i = 0 To 9
If InStr(1, myString, i) > 0 Then
myOtherString = "Blah"
End If
Next i
If myOtherString <> "Blah" Then
MsgBox "no numbers found"
Else
MsgBox "numbers found"
End If

Cheers,
Mike.
Mike (15)
1