View Single Post
 
Old 01-13-2021, 03:04 AM
alex100 alex100 is offline Windows 7 64bit Office 2016
Advanced Beginner
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default Find and replace only the last match

The code below will find and replace all keywords in a selection.

Code:
With Selection.Find
    .ClearFormatting
    .Text = "keyword"
    .Replacement.Text = "replacement_keyword"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
How can I rewrite it so that it will only replace the last keyword in the selection? So, if it happens there are multiple keywords in the text, only the last match should be replaced, while the others before it should not be changed.

Alex
Reply With Quote