The following code will replace characters in a string with a replacement string similar to @ReplaceString formula.
It also supports multiple characters for the search string (the substring part to be replaced)
Alternate:
Function StrReplaceSlashes(startStr As String, replaceChr As String, newChr As String) As String
Dim newStr As String
On Error GoTo FErrorHandler
newStr = startStr
If (replaceChr = "") Then
StrReplaceSlashes = startStr
End If
Do While InStr(newStr, replaceChr) > 0
newStr = Left$(newStr, InStr(newStr, replaceChr)-1) + newChr + Right$(newStr,Len(newStr)-Instr(newStr, replaceChr))
Loop
StrReplaceSlashes = newStr
FExit:
Exit Function
FErrorHandler:
StrReplaceSlashes = startStr
Resume FExit
End Function
previous page
|