Finding a Substring?

G

Guest

Try something like this:

With
A1: abcaaaaaaaaaadddddddabczzzzzzzzzzzzzabcyyyyy

This formul returns the starting position of the last occurrence of "abc"
=SEARCH("|",SUBSTITUTE(A1,"abc","|",(LEN(A1)-LEN(SUBSTITUTE(A1,"abc","")))/LEN("abc")))

Is that something you can work with?
***********
Regards,
Ron

XL2002, WinXP
 
G

Guest

I'm in the mood today to write my own functions. try this

Function FindLast(ShortString, LongString) As Integer

Shortlength = Len(ShortString)
LongLength = Len(LongString)

FindLast = 0
If (Shortlength <= LongLength) Then

StringPosition = LongLength - Shortlength + 1

For i = StringPosition To 1 Step -1

If (StrComp(ShortString, Left(Mid(LongString, i, Shortlength),
Shortlength)) = 0) Then
FindLast = i
Exit For
End If


Next i

End If

End Function
 
G

Guest

Thank you very much.


--
jake


Joel said:
I'm in the mood today to write my own functions. try this

Function FindLast(ShortString, LongString) As Integer

Shortlength = Len(ShortString)
LongLength = Len(LongString)

FindLast = 0
If (Shortlength <= LongLength) Then

StringPosition = LongLength - Shortlength + 1

For i = StringPosition To 1 Step -1

If (StrComp(ShortString, Left(Mid(LongString, i, Shortlength),
Shortlength)) = 0) Then
FindLast = i
Exit For
End If


Next i

End If

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top