R
RB Smissaert
This might suit you and it is fast:
Function PositionFirstNumberInString(strString As String) As Long
Dim i As Long
Dim btArray() As Byte
btArray = strString
For i = 0 To UBound(btArray) Step 2
If btArray(i) > 47 And btArray(i) < 58 Then
PositionFirstNumberInString = i \ 2 + 1
Exit Function
End If
Next
PositionFirstNumberInString = -1
End Function
Use it like this:
If PositionFirstNumberInString("aaaaa2bbbbb3mmmmm") > -1 Then
Msgbox "this string has a digit, so answer is True"
End If
You could change the function to a Boolean output if you want, but it makes
sense
to keep the position information.
RBS
Function PositionFirstNumberInString(strString As String) As Long
Dim i As Long
Dim btArray() As Byte
btArray = strString
For i = 0 To UBound(btArray) Step 2
If btArray(i) > 47 And btArray(i) < 58 Then
PositionFirstNumberInString = i \ 2 + 1
Exit Function
End If
Next
PositionFirstNumberInString = -1
End Function
Use it like this:
If PositionFirstNumberInString("aaaaa2bbbbb3mmmmm") > -1 Then
Msgbox "this string has a digit, so answer is True"
End If
You could change the function to a Boolean output if you want, but it makes
sense
to keep the position information.
RBS