Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-13-2021, 03:04 AM
alex100 alex100 is offline Find and replace only the last match Windows 7 64bit Find and replace only the last match Office 2016
Advanced Beginner
Find and replace only the last match
 
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you use the find and replace tool to find dates and times in Excel 2013? Jules90 Excel 3 04-14-2020 07:40 PM
In Find and Replace, can Word stop after each Replace? wardw Word 1 06-08-2017 02:47 PM
Find and replace only the last match Find a match and move row to top of page Auto Excel Programming 3 03-08-2016 01:17 AM
Find and replace only the last match Find what box in Find and replace limits the length of a search term Hoxton118 Word VBA 7 06-10-2014 05:05 AM
Find and replace only the last match Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:50 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft