rob@xxxxxxxxx wrote:
If I want to find a string beginning from the right in excel how do I do it? For example, given the string
/mydir/mysubdir/mydata.txt
I want to find the position of the last slash. I should get a 16.

I see you've found a solution, here's a user defined function if you'd rather use it:


Function FindR(inValue As String, strFind As String) As Integer

Dim strString As String
Dim intLength As Integer, x As Integer

strString = RTrim(inValue)
intLength = Len(strString)

For x = 0 To intLength - 1
FindR = intLength - x
If Mid(strString, FindR, 1) = strFind Then Exit Function
Next x

FindR = -1

End Function

If your sample string is in cell A1:
=findr(a1,"/") returns 16
=findr(a1,".") returns 23

Bill

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.