I'm using this macro--which works fine in Sub format:
Sub replaceStringInCells()
Dim wTxt As String
Dim rTxt As String
Dim rNum As Integer
rNum = 0
For Each Row In Range("swapvalues").Rows '<== change the wordlist Name here as required
wTxt = Row.Cells(1).Value
rTxt = Row.Cells(2).Value
Selection.Replace What:=wTxt, Replacement:=rTxt, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
rNum = rNum + 1
Next
End Sub
I've tried to change it to a function--by changing Sub to Function, updating the Function name, and adding string parameters:
Function replaceaccents(thestring As String)
Dim wTxt As String
Dim rTxt As String
Dim rNum As Integer
rNum = 0
For Each Row In Range("swapvalues").Rows '<== change the wordlist Name here as required
wTxt = Row.Cells(1).Value
rTxt = Row.Cells(2).Value
Selection.Replace What:=wTxt, Replacement:=rTxt, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
rNum = rNum + 1
Next
replaceaccents = thestring
End Function
But, this just outputs the original cell.
Is there a way I can make this work as a function?
Thanks!