Replace a constant with an incrementing number

C

chumba_dude

Is there a way in Word to replace a constant with a self incrementing number?
For example, I have a 500+ page Word document, it has a fixed phrase XYZ
repeated many, many times in the document. I need to replace XYZ with a self
incrementing number where I can specify what the starting number would be;
first occurance of XYZ becomes 101000, second occurance of XYZ becomes 101001
etc.
Can I use 'Find and Replace' for what I need to do? Or do I have to get
into Macros?
 
H

Herb Tyson [MVP]

I would create an SEQ field as the counting "seed". Then copy it to the
clipboard so it can be referenced as ^c in the replace field. Finally, I'd
Find/Replace XYZ with ^c.

First... replace the first XYZ with the initial SEQ field that establishes
the starting value. Press Ctrl+F9 (insert field braces) and inside the field
braces type:

seq chumbanumba \r101000

and then press F9. This will create the initial sequence number, 101000.

Second... replace the 2nd XYZ with the instance of the seq field that you
will copy to the clipboard. Press Ctrl+F9 and inside the field braces type:

seq chumbanumba

at the moment, this will look like { seq chumbanumba }. Select the entire
field (including braces) and copy it to the clipboard (Ctrl+C).

Third... press Ctrl+H, and inscribe the Replace/With fields as:

Find what:XYZ

Replace with:^c

Then click Replace All

Finally... select the entire document (Ctrl+A) and update all of the field
codes (Ctrl+F9).

If you don't have any other field codes in the document, you can convert the
fields into "hard" numbering by selecting the document and pressing
Ctrl+Shift+F9.
 
C

chumba_dude

Thank you so much, I will try it later..

Herb Tyson said:
I would create an SEQ field as the counting "seed". Then copy it to the
clipboard so it can be referenced as ^c in the replace field. Finally, I'd
Find/Replace XYZ with ^c.

First... replace the first XYZ with the initial SEQ field that establishes
the starting value. Press Ctrl+F9 (insert field braces) and inside the field
braces type:

seq chumbanumba \r101000

and then press F9. This will create the initial sequence number, 101000.

Second... replace the 2nd XYZ with the instance of the seq field that you
will copy to the clipboard. Press Ctrl+F9 and inside the field braces type:

seq chumbanumba

at the moment, this will look like { seq chumbanumba }. Select the entire
field (including braces) and copy it to the clipboard (Ctrl+C).

Third... press Ctrl+H, and inscribe the Replace/With fields as:

Find what:XYZ

Replace with:^c

Then click Replace All

Finally... select the entire document (Ctrl+A) and update all of the field
codes (Ctrl+F9).

If you don't have any other field codes in the document, you can convert the
fields into "hard" numbering by selecting the document and pressing
Ctrl+Shift+F9.

--
Herb Tyson MS MVP
Author of the Word 2007 Bible
Blog: http://word2007bible.herbtyson.com
Web: http://www.herbtyson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top