Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Find first non numeric character in string

I want to strip out the first part of a string so that the result starts with
the first non numeric character. The second numeric value (19184 in the
example below) is an id that can vary in length so I can't just use the mid
function as the starting point will vary.

Example:

"1 - 19184 - BP Trowbridge Lodge Service Station"

I want to return "BP Trowbridge Lodge Service Station"

Thanks for any help

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default Find first non numeric character in string

Is the " - " always going to be there? If so you can look for that.
--
Charles Chickering

"A good example is twice the value of good advice."


"Snowsride" wrote:

I want to strip out the first part of a string so that the result starts with
the first non numeric character. The second numeric value (19184 in the
example below) is an id that can vary in length so I can't just use the mid
function as the starting point will vary.

Example:

"1 - 19184 - BP Trowbridge Lodge Service Station"

I want to return "BP Trowbridge Lodge Service Station"

Thanks for any help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Find first non numeric character in string

try this:
Public Function GetAlphaString(strMyString) As String
Dim i As Integer
Dim iAsc As Integer
For i = 1 To Len(strMyString)
iAsc = Asc(Mid(strMyString, i, 1))
If (iAsc = 65 And iAsc <= 90) Or (iAsc = 97 And iAsc <= 122) Then
GetAlphaString = Right(strMyString, Len(strMyString) - i + 1)
Exit For
End If
Next i
End Function

(or change the if statement to 'select case' - it's easier to read)

jp

"Charles Chickering" wrote:

Is the " - " always going to be there? If so you can look for that.
--
Charles Chickering

"A good example is twice the value of good advice."


"Snowsride" wrote:

I want to strip out the first part of a string so that the result starts with
the first non numeric character. The second numeric value (19184 in the
example below) is an id that can vary in length so I can't just use the mid
function as the starting point will vary.

Example:

"1 - 19184 - BP Trowbridge Lodge Service Station"

I want to return "BP Trowbridge Lodge Service Station"

Thanks for any help

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Find first non numeric character in string

If the general format of the string is always the same then you could take
all text after the final "-":

Function GetName(strIn As String) As String
'''Returns text after the final "-" in strIn
' Returns "" if no "-" found
Dim iPos As Integer

iPos = InStrRev(strIn, "-")
If iPos = 0 Then
GetName = ""
Else
GetName = Application.Trim(Right(strIn, Len(strIn) - iPos))
End If
End Function

if this won't work and you really want to start with the first alpha
character then use this:

Function GetName2(strIn As String) As String
'''Returns text stating with the first alpha character
' Returns "" if no alpha characters are found
' Note: ASCII "A" = 65, "Z" = 90, "a" = 97, "z" = 122
Dim iPos As Integer, iLen As Integer, iAsc As Integer

iLen = Len(strIn)
For iPos = 1 To iLen
iAsc = Asc(Mid(strIn, iPos, 1))
If (iAsc 64 And iAsc < 91) Or (iAsc 96 And iAsc < 123) Then
Exit For
End If
Next iPos

If iPos iLen Then
'no alpha characters found in string
GetName2 = ""
Else
GetName2 = Application.Trim(Right(strIn, Len(strIn) - iPos + 1))
End If
End Function

To use these functions, code something like this:

Sub Test()
Dim strResult

strResult = GetName2("1 - 19184 - BP Trowbridge Lodge Service Station")
MsgBox strResult
End Sub

Cheers,
Dave


"Snowsride" wrote:

I want to strip out the first part of a string so that the result starts with
the first non numeric character. The second numeric value (19184 in the
example below) is an id that can vary in length so I can't just use the mid
function as the starting point will vary.

Example:

"1 - 19184 - BP Trowbridge Lodge Service Station"

I want to return "BP Trowbridge Lodge Service Station"

Thanks for any help

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 numeric value at end of string Barb Reinhardt Excel Worksheet Functions 13 February 4th 06 11:31 PM
function for finding position of numeric character in a string Paul Excel Programming 5 February 6th 05 12:19 AM
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 02:59 PM.

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

About Us

"It's about Microsoft Excel"