Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Find postion of number character within a string
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Find postion of number character within a string
thanks jim spot on
"Jim Thomlinson" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
FIND 2nd character in a string | Excel Worksheet Functions | |||
find a character in a string | Excel Discussion (Misc queries) | |||
Find first non numeric character in string | Excel Programming | |||
Find nth instance of a character in a string | Excel Discussion (Misc queries) | |||
backwards find function to find character in a string of text | Excel Programming |