Software

A Find and Replace trick for inserting new text

Want to insert new text throughout a document without risking errors or typos? Try this simple Find and Replace technique.
You can't use Word (or any Office application) too long without learning a few Find and Replace tricks. This feature really works hard to help you overcome tedious editing tasks. What you might not know is that you can use this feature to insert text. For example, if you wanted to add a newly acquired title to your name, you could search for every occurrence of your name and add the title manually. You might use Find and Replace to search for your name, using the full replacement string as follows: John Doe, MCSE. Both methods will work, but there's a simpler way: Use the ^& code in the Replace With value. The ^& code tells Find and Replace to add the text in the Find What entry to the replacement text. In our simple name example, you'd use the following settings: Find What: John Doe Replace With: ^&, MCSE In such a simple example, it hardly seems to matter, but your task won't always be this simple. You might need to insert text both before and after an existing string or the existing string might be long and unfamiliar, opening the door for typos, which can be hard to troubleshoot in a Find and Replace task. Using ^& to represent the Find What string is an easy way to insert text and keep the Find What string intact.

About

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

47 comments
oilonye
oilonye

I think it'll reduce the time spent working on a particular document. Ds is a good discovery.

oscarsr1
oscarsr1

definately one you need to remember...

mirossmac2
mirossmac2

If you have a piece of boilerplate text to insert in several places in a document, put an empty string, like @@@@, as a marker where you need the insertions. Then copy the boilerplate text to the clipboard, Find @@@@, and Replace with ^c. The Replace box itself cannot hold more than 255 characters, so this will get round that restriction.

RU7
RU7

Can anyone explain why using wild cards eliminates the capability to find paragraph marks?

dan
dan

A task I need to perform often is to eliminate extra paragraph returns or line breaks. The trick is that double returns are the real ones that you want to keep. This is what I do: Replace ^p^p with @@@@ or some other nonsense string. Next, replace ^p with nothing, then, replace @@@@ with ^p^p. Now you have your real paragraph breaks and no extra ones.

jbackerman
jbackerman

What a helpful tip. Where can you find other possible codes to use?

miaperry
miaperry

Try this on the article: Find: in tact Replace with: intact Interesting tip, thanks!

mirossmac2
mirossmac2

You can get rid of all comments with Find/Replace, too. Just put ^a in the Find box and leave the Replace box empty.

Tink!
Tink!

Now I only have to [b]remember[/b] this one. :)

Mike Karp
Mike Karp

Well, OK. But do we really need an alternative to a simple copy and paste from the "find what" box?

Kojaks43
Kojaks43

"You might need to insert text both before and after an existing string" Understood the ^& for after a string, but unsure how to add text before the string. Any guidance would be appreciated.

Kim SJ
Kim SJ

Of course, if you're searching with wildcards, then knowing the original text is even more useful. And better still, \1, \2 etc. will refer to "grouped" components of the match, indicated by parentheses. Try (a)([0-9]@)> as the search pattern, with Original was "^&", elements were "\1", "\2". as the replace, on a list of numbers such as a12 b34 a56 a1 Word's f1 help is actually quite helpful for once, on this subject.

Thack
Thack

That's cool. Thanks, Susan, I didn't know about that.

SirWizard
SirWizard

If you actually use large standard boilerplate selections often, don't use Find & Replace. Turn the boilerplate items into AutoText entries, so you can select them from the menu [Word 2003]. From the menu, click Insert > AutoText > AutoText... to set it up. The entries are stored within the Template files.

dhays
dhays

No one has explained how to insert the replacement text ONLY where you want it, nowhere else. In an Excel document, I often change out limits on a summation, to expand or contract the area being summed, to do that I use the find/replace, but if I don't do it by highlighting the area to search and replacing one cell at a time, I can change something I don't want changed. Then you have to undo the change or find what changed erroneously and change it back to what it should be. "round that restriction" by microssamc2 should be "around..." More spelling: (mike.smith1018) "asterics or something else" asterisk is how it is spelled

mirossmac2
mirossmac2

^p doesn't work when wildcards are on and, yes, it is baffling - especially when ^13 finds paragraph marks perfectly in the same circumstances.

RU7
RU7

I prefer the before and after spacing for paragraphs. BTAIM, this type of issue occurs frequently with email that is wrapped to a window when copied. If the text in question is not too long I sometimes do this. Find = ^p Replace = [space] Click "Find Next". From then on, as each new ^p is found; if you want to keep it, press the "f" key; if not, press the "r" key. You can zoom through a large hunk of text pretty quickly.

kohl
kohl

To eliminate extra paragraph returns (such as when pasting text from a text file) use the above in modified form. For those single paragraph returns that you want to keep (as in a signature block for example) replace ^p (Find & Replace, More, Special, Paragraph Mark) with, for example, ####, in addition to replacing ^p^p with @@@@. And, when you then replace the remaining ^p's in the document, you will usually want to replace them with a space instead of nothing. Then replace @@@@ with ^p^p and #### with ^p.

ian
ian

I'd like to know where to find the codes too. great tip.

RanEd
RanEd

Funny . . . don't you love spelling. . .

aksalaymeh
aksalaymeh

Hi, It works with Word 2010 but not Excel 2010!!!

RU7
RU7

you need to use this. If you are looking for a variety of possibilities. Here is a good example of the synergy of combining Word and Excel. I had a large list, hundreds, of numbers. They were a latitude with 2 digits, i.e., leading zeros, and 8 decimal places; followed by longitude with 3 digits and 8 decimal places; and an elevation angle with 2 digits and 8 decimal places. In Word, I needed to insert a tab between each number and eliminage everything else on each line so it could be copied into Excel in 3 columns. First, since finding paragraph marks with wild cards doesn't work, leave wild cards unchecked and replace all of the paragraph marks (^p) with linefeeds (^l). Add a linefeed as the first character in the document. Then check the wild cards and: Find ^l(??.????????)(???.????????)(??.????????)*^l Replace \1^t\2^t\3^l Now copy it into Excel and you have 3 separate columns to work with, latitude, longitude, and elevation; to sort, find, or graph at will.

ssharkins
ssharkins

Just add the text before the code: Find What: Susan Harkins Replace With: Ms. ^&, MSCE

Varseller
Varseller

Hi Kim, That sounds like something very powerful. I'm not sure I got the full meaning of what it can do. can you give another example? Thanks!

mike.smith1018
mike.smith1018

In some documents, when you translate them, you actually also have to change dashes at the beginning of the paragraph for asterics or something else. The only luck is that they are followed by tab. So what I do si that I replace "-^t" by "*^t" and it is done. Great tool Mike Smith http://www.mswordhelp.com

SirWizard
SirWizard

Word's Find & Replace supports all sorts of wildcards and regular expressions, including limited specific characters and NOT characters. Look at the Help topic for "Find and replace text or other items" and click Show All. [Word 2003. I don't know what's in the UI-crippled Word 2007]

RU7
RU7

Seems to me that a better way to do something like that would be to have a cell for the upper and the lower limit, then reference those in your calculations. When you want to change the limits, just change the values in the referenced cells.

mirossmac2
mirossmac2

Don't be so parochial, man! To get round [some difficulty], physical or metaphorical, is perfectly good English among those who invented the language in the first place - and I hope we never get around to adopting the worst of the pedantries your lot has latterly introduced.

RU7
RU7

But d#%n why didn't I figure that out on my own instead of being lazy. I will no longer replace all ^p with ^l, do my wildcard stuff, then replace all ^l with ^p.

SirWizard
SirWizard

Look at the Word Help topic for "Find and replace text or other items" and click Show All. [Word 2003]. It shows all sorts of very powerful codes for wildcards and regular expressions.

mirossmac2
mirossmac2

Word Tips at VitalNews.com has an entire CD Rom of Find/Replace routines, including off-the-peg macros for really complex stuff - probably more than any one user ever needs.

jeffer3
jeffer3

Mike, thank you for a (very) helpful link. Seems so simple I am kicking myself!LOL

svogel
svogel

supports that! Same goes for Access -- many of their database templates violate basic normalization rules. It's frustrating...they teach bad habits from the very beginning.

SirWizard
SirWizard

Microsoft is a major offender when it comes to bad documentation formatting. Too many times, a Microsoft application opens a dialog box or provides "so-called" information [help that doesn't help] that completely violates the Microsoft Manual of Style for Technical Publications, simple common sense, or both. The worst offenses against sensibility are the frequent message boxes that report some completely unacceptable situation, while offering only an "OK" button for what is NOT okay. Anybody with a bit of sense (not Microsoft management) would label a bad-news message box with a "Close" button instead.

bulk
bulk

I just bought a copy - looks good! Richard

RU7
RU7

at the end of sentences. It helps set the division apart, especially from other uses of the period. Single spaced sentences and the optionallity (is that a word?) of a comma before the "and" of the last thing in a comma separated group of three or more things, are, IMO, unfortunate items in the new punctuation rules. I consider them similar to adding "nu-kya-ler" as a correct pronunciation for nuclear.

mirossmac2
mirossmac2

WordTips at www.vitalnews.com has just published its fourth "Styles and Templates" manual as a download PDF or a CD-Rom (which also has the manual in .doc format). They also do daily free tips with a bonus four on Saturdays (8 for subscribers). I hated Word until I subscribed but now it amazes me daily at how it's ahead of every problem I meet.

bulk
bulk

who did all the things you mentioned, and also makes heavy use of styles - so much less work! I've even had Word docs from Microsoft that have the most appalling formatting and that show the author had absolutely no idea how to use Word properly. It's a point of honour to me to produce a usermanual without a single instance of ^p^p anywhere. But I'd really love to see a clear, structured article on using, creating and modifying styles, especially in Word 2010. I still have to work harder with these than I should, and I'm sure most ignore them, don't appreciate them or simply don't understand how useful styles are. RS

SirWizard
SirWizard

Properly formatted/styled Word documents rarely if ever need two paragraph marks in sequence. I write multi-hundred page user manuals in Word without sequential pilcrows (paragraph marks). By setting paragraph Space Before and Space After formatting, especially in styles, I produce very clean and stable documents. That's Find: ^p^p Replace: ^p I also Find & Replace away trailing blanks or trailing tabs just before a pilcrow. I often "fix" documents for Word users who complain of extra blank pages that print at the end. Users who don't keep non-printing characters visible (I call it flying blind) sometimes have many pages of "invisible" sequential paragraphs containing only returns, blanks, and tabs. For blank spaces, that's Find: blank^p Replace: ^p [where "blank" means a single spacebar press] --AND-- For tabs, that's Find: ^t^p Replace: ^p I also throw away double-blank characters. Many documents have a lot of them because "ancient" typists were taught to follow the closing punctuation of a sentence with two blanks, and modern folks don't realize that this old rule was meant for monospaced typewriters, NOT for modern proportional-font word processors. Word has an option for setting to the modern single blank after a sentence (or double blank for those who eschew modern improvements and prefer to mount horseshoes on a car instead of radial tire/tyres.) That's Find: blankblank Replace: blank [where "blank" means a single spacebar press] When removing double blanks or double pilcrows, just repeat Replace All until Word reports zero changes. Each repeat works exponentially, so ten repeats will remove any repeated spaces nested more than a thousand deep.

mike.smith1018
mike.smith1018

I am glad that you liked the link. And if you know how to, everything is simple :-) mike