msfz751

VBA Function - show and replace string inside brackets

Oct 2nd, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Function - show and replace string inside brackets - v1.xls
  2. 'This example replaces the index inside brackets.
  3. 'Useful when a command must read more components
  4. 'of what is the default in the Export file
  5. '============================================================
  6. Function ReplaceIndex(str As String, iDel As String, fDel As String, newIdx As String)
  7. 'this function replaces the index inside brackets and replace is with
  8. Dim midStr As String
  9.     On Error GoTo error1
  10.     midStr = Mid(str, WorksheetFunction.Find(iDel, str) + 1, _
  11.              WorksheetFunction.Find(fDel, str) _
  12.            - WorksheetFunction.Find(iDel, str) - 1)
  13.     ReplaceIndex = WorksheetFunction.Replace(str, WorksheetFunction.Find(iDel, str) _
  14.                     + 1, Len(midStr), newIdx)
  15.     Exit Function
  16. error1:
  17.     ReplaceIndex = "Incorrect delimiter"
  18.     Application.Calculate
  19. End Function
Advertisement
Add Comment
Please, Sign In to add comment