VBA. How to find position of first digit in string

Ololovin picture Ololovin · Aug 23, 2010 · Viewed 38.7k times · Source

I have string "ololo123". I need get position of first digit - 1. How to set mask of search ?

Answer

Spere picture Spere · Aug 6, 2015

Here is a lightweight and fast method that avoids regex/reference additions, thus helping with overhead and transportability should that be an advantage.

Public Function GetNumLoc(xValue As String) As Integer

For GetNumLoc = 1 To Len(xValue)
    If Mid(xValue, GetNumLoc, 1) Like "#" Then Exit Function
Next

GetNumLoc = 0

End Function