View Single Post
  #4   Report Post  
Jim Cone
 
Posts: n/a
Default

Francis,

And the following gets you the position using code ...
'-----------------------------------------------------------------------------------
Function LastPosition(ByVal strInput As String, ByVal strChars As String) As Long
'Jim Cone - San Francisco - Sep 18, 2003
'ByVal allows variants to be used for the string variables
On Error GoTo WrongPosition
Dim lngPos As Long
Dim lngCnt As Long
Dim lngLength As Long

lngPos = 1
lngLength = Len(strChars)

Do
lngPos = InStr(lngPos, strInput, strChars, vbTextCompare)
If lngPos Then
lngCnt = lngPos
lngPos = lngPos + lngLength
End If
Loop While lngPos 0
LastPosition = lngCnt
Exit Function

WrongPosition:
Beep
LastPosition = 0
End Function

'Call it like this...
Sub WhereIsIt()
Dim N As Long
N = LastPosition("http://www.theexceladdict.com/tutorials.htm", "/")
MsgBox N
End Sub
'----------------------------------------

Regards,
Jim Cone
San Francisco, USA


"Francis Hayes (The Excel Addict)"
wrote in message
...
I'm sure I've done this in the past but for the life of me I can't remember
it now.
Say I have a string "http://www.theexceladdict.com/tutorials.htm" in cell
A1. I want to determine the position of the last "/" (forward slash). The
strings won't always contain the same # of "/"s.
I need to be able to do this as a formula and also in VBA code.
I appreciate your help.
--
Have a great day,
Francis Hayes (The Excel Addict)
http://www.TheExcelAddict.com
Helping Average Spreadsheet Users
Become Local Spreadsheet Experts