0

I want to replace multiple text / punctuation marks for example

"," with " "

"'s" with " "

, 's are Extra text which I do not need for next step.

Replace method can change only one time

Is there any other way to replace multiple text from the following sentence?

"Aabar remains focused on Abu Dhabi’s plans expansion, In Dubai ahead of Expo 2020"

Replace works with , but 's is still there.

Sub make_range_replace_string()
Dim R As Range
Dim F As String
Do
    selection.Find.ClearFormatting
    selection.Find.Font.Bold = True
    With selection.Find
        .Forward = True
        .Wrap = wdFindStop
    End With
    selection.Find.Execute
    If selection.Find.Found Then
   Set R = ActiveDocument.Range(selection.Range.Start, selection.Range.End)

   F = Replace(R, ",", "") 

   MsgBox F

Else
Exit Do
End If
Loop

End Sub
3
  • 1
    You can nest the Replace functions like F = Replace(Replace(R, ",", "") ,"'s", " "). Commented May 15, 2016 at 14:43
  • @DougGlancy Replace works with , but 's is still there. what should I do? Commented May 15, 2016 at 14:56
  • 1
    Create a two-dimensional array with all the replacement-words and iterate through the list with the above posted code. Commented May 15, 2016 at 15:33

1 Answer 1

2

Doug Glancey is correct, just use ’ instead of ' though. In other words; use the Replace-function multiple times.

Dim F As String

F = "Aabar remains focused on Abu Dhabi’s plans expansion, In Dubai ahead of Expo 2020"
F = Replace(F, ",", " ")
F = Replace(F, "`s", " ")
F = Replace(F, "’s", " ")
F = Replace(F, "'s", " ")
F = Replace(F, Chr(39) & "s", " ")
F = Replace(F, Chr(96) & "s", " ")

MsgBox F
Sign up to request clarification or add additional context in comments.

2 Comments

as you notice 's is attached to the text, so Replace(F, "’s", " ") is not working. There should be another way?
Strange, I've edited the answer with more variations of the 's

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.