Private Sub Command1_Click()
Dim oldstring As String, newletter As String, _ oldletter As String, newstring As String oldstring = "hello To the world" newletter = "YEAH" oldletter = "hello" newstring = Replace(oldstring, newletter, oldletter) MsgBox newstring End Sub Public Function Replace(oldstring, newletter, oldletter) As String Dim i As Integer i = 1 Do While InStr(i, oldstring, oldletter, vbTextCompare) <> 0 Replace = Replace & Mid(oldstring, i, _ InStr(i, oldstring, oldletter, vbTextCompare) - i) & newletter i = InStr(i, oldstring, oldletter, vbTextCompare) + Len(oldletter) Loop Replace = Replace & Right(oldstring, Len(oldstring) - i + 1) End Function Inputs:oldstring, newletter, oldletter |