Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-01-2014, 07:51 PM
kfs kfs is offline Find and Replace "find what text" Windows 7 64bit Find and Replace "find what text" Office 2010 32bit
Novice
Find and Replace "find what text"
 
Join Date: Sep 2014
Posts: 3
kfs is on a distinguished road
Default Find and Replace "find what text"


In a long list of references, I'm trying to find each instance of a calendar year and replace it with that same year enclosed by parentheses. For example, find "1991" and replace with "(1991)"; find "2007" and replace it with "(2007)". I have no problem finding the years, but can't seem to crack the code on replacing and inserting the parens.
Reply With Quote
  #2  
Old 09-01-2014, 08:20 PM
macropod's Avatar
macropod macropod is offline Find and Replace "find what text" Windows 7 64bit Find and Replace "find what text" Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could use a wildcard Find/Replace, where:
Find = <[0-9]{4}>
Replace = (^&)
The < and > tell Word the number can't be part of a larger string (e.g. 5 digits), whilst the [0-9]{4} tells Word to find a 4-digit string. The Replace expression tells Word to insert ( and ) either side of the found content, which is indicated by the ^&.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 09-01-2014, 08:36 PM
kfs kfs is offline Find and Replace &quot;find what text&quot; Windows 7 64bit Find and Replace &quot;find what text&quot; Office 2010 32bit
Novice
Find and Replace &quot;find what text&quot;
 
Join Date: Sep 2014
Posts: 3
kfs is on a distinguished road
Default

OK, thanks. I see that works when I turn "Track Changes" off. When "Track Changes" is on, it returns the year followed by (). Not sure why, but am happy with the fix. Thanks again!
Reply With Quote
  #4  
Old 09-01-2014, 08:50 PM
macropod's Avatar
macropod macropod is offline Find and Replace &quot;find what text&quot; Windows 7 64bit Find and Replace &quot;find what text&quot; Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your original post didn't mention anything about track changes. To work with those, you'd need to use a macro that, instead of replacing the found string, inserts the brackets before & after:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "<[0-9]{4}>"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    .InsertBefore "("
    .InsertAfter ")"
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 09-02-2014, 03:54 PM
kfs kfs is offline Find and Replace &quot;find what text&quot; Windows 7 64bit Find and Replace &quot;find what text&quot; Office 2010 32bit
Novice
Find and Replace &quot;find what text&quot;
 
Join Date: Sep 2014
Posts: 3
kfs is on a distinguished road
Default

OK, thanks again
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Replace &quot;find what text&quot; Help with the "find and replace" option; character problem martinn4 Word 3 02-20-2014 03:52 AM
can find and replace instances of the "enter" key? snunicycler Word 7 05-02-2013 11:54 PM
Find and Replace &quot;find what text&quot; Word Macro to find and delete rows that contain adjacent cells containing "." AlexanderJohnWilley Word VBA 7 11-08-2012 10:15 AM
Find and Replace &quot;find what text&quot; Is there a way to use "find/replace" to find italics words? slayda Word 3 09-14-2011 02:16 PM
Find and Replace &quot;find what text&quot; Find & Replace words with "/" prefix & suffix tollanarama Word 4 01-25-2011 02:19 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:08 AM.


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