Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
FIND 2nd character in a string Fuzzy Excel Worksheet Functions 7 September 1st 09 08:14 AM
find a character in a string kevcar40 Excel Discussion (Misc queries) 4 June 5th 07 12:10 PM
Find first non numeric character in string Snowsride Excel Programming 3 November 14th 06 05:49 PM
Find nth instance of a character in a string Francis Hayes (The Excel Addict) Excel Discussion (Misc queries) 7 January 21st 05 03:44 PM
backwards find function to find character in a string of text Ashleigh K. Excel Programming 1 January 14th 04 04:36 PM


All times are GMT +1. The time now is 09:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"