Search and replace entire string
Use this function to do a search and replace function. It works by finding
the next instance of the string that you are looking for, and gets everything to the left
and right of it, inserting the new string between the two parts.
Public Function replaceall(searchstring As String, _
findstring As String, replacestring As String) As String
Dim curpos As Long
curpos = 1
Do
curpos = InStr(curpos, searchstring, findstring)
searchstring = Left$(searchstring, curpos - 1) & _
replacestring & Right$(searchstring, Len(searchstring) _
- curpos - Len(findstring) + 1)
Loop Until InStr(searchstring, findstring) = 0
replaceall = searchstring
End Function
You could easily modify this function
to search only a certain range of the string, if you needed
to.
|