View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default Find postion of number character within a string

This should do it... It returns -1 if no number is found...

Public Function LastNumber(ByVal InputString As String) As Integer
Dim intCounter As Integer
Dim intStringLength As Integer
Dim intReturnValue As Integer

intReturnValue = -1
intStringLength = Len(InputString)

For intCounter = intStringLength To 1 Step -1
If IsNumeric(Mid(InputString, intCounter, 1)) Then
intReturnValue = intCounter
Exit For
End If
Next intCounter

LastNumber = intReturnValue
End Function
--
HTH...

Jim Thomlinson


"mcphc" wrote:

I need some code to find the position of the last number character within a
string.

The string could be any length and may or may not have a number character.

for example a function that would do this:

pos = PosNum("Vessel 8 (2)") 'pos equals 11

Any ideas?

Thanks