substring operation

  • Thread starter Thread starter jana
  • Start date Start date
J

jana

hi ,
is there a way to find the n'th instance of a substring in its
parent string ?

regards,
jana
 
Hi, here are a couple of examples that may help ...


Sub FindReplaceNthVal()
Dim strLook As String
Dim strFind As String
Dim lngInst As Long
Dim strFinal As String
strLook = "again1again2again3again4again5again6again7again8"
strFind = "again"
lngInst = 4
strFinal = WorksheetFunction.Substitute(strLook, strFind, "", lngInst)
MsgBox strFinal
End Sub
Sub FindNthPosition()
Dim strLook As String
Dim strFind As String
Dim lngInst As Long
Dim lngPos As Long
Dim strFinal As String
Dim strWhole As String
strLook = "again1again2again3again4again5again6again7again8"
strFind = "again"
lngInst = 4
strFinal = WorksheetFunction.Substitute(strLook, strFind, "~", lngInst)
lngPos = InStr(1, strFinal, "~")
strWhole = Mid(strLook, lngPos, Len(strFind))
End Sub


HTH
 

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

Back
Top