Search and Replace and/or Macro

R

Rebecca

Greetings.

I am using MS WORD 2002 (Office XP), and I would like to
do the following. I have many paragraphs that are headed
by numbers, such as

12 blah, blah
2 blah, blah
222 blah, blah
1354 blah, blah
43 blah, blah and so on.

I want to sort these paragraphs, but I will have to put
three zeros before the paragraphs with one digit numbers,
two zeros before the paragraphs with two digit numbers,
one zero before the paragraphs with three digit numbers,
and no zeros before the paragraphs with four digit numbers
(the largest numbers), so the result should look as
follows:

0012 blah, blah
0002 blah, blah
0222 blah, blah
1354 blah, blah
0043 blah, blah and so on.

How can this be done (hopefully in search and replace),
but if a macro is needed could you please explain in very
easy English? Thanks a million.
 
R

Rebecca

Thanks, Doug, but I when I run the macro I get an error
message at this row

Do While .Execute(FindText:="^13[0-9]{1,} ",
MatchWildcards:=True,

What should I do now?

-----Original Message-----
Hi Rebecca,

The following macro using a Wildcard Find will convert all but the number at
the beginning of the first paragraph in the document:

Dim numrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="^13[0-9]{1,} ", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
Set numrange = Selection.Range
numrange.Start = numrange.Start + 1
numrange.End = numrange.End - 1
numrange.Text = Format(numrange.Text, "000#")
Loop
End With

To learn more about wildcards, see the article "Finding and replacing
characters using wildcards" at:

http://www.mvps.org/word/FAQs/General/UsingWildcards.htm

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Rebecca said:
Greetings.

I am using MS WORD 2002 (Office XP), and I would like to
do the following. I have many paragraphs that are headed
by numbers, such as

12 blah, blah
2 blah, blah
222 blah, blah
1354 blah, blah
43 blah, blah and so on.

I want to sort these paragraphs, but I will have to put
three zeros before the paragraphs with one digit numbers,
two zeros before the paragraphs with two digit numbers,
one zero before the paragraphs with three digit numbers,
and no zeros before the paragraphs with four digit numbers
(the largest numbers), so the result should look as
follows:

0012 blah, blah
0002 blah, blah
0222 blah, blah
1354 blah, blah
0043 blah, blah and so on.

How can this be done (hopefully in search and replace),
but if a macro is needed could you please explain in very
easy English? Thanks a million.


.
 
D

Doug Robbins - Word MVP

Hi Rebecca,

The whole of

Do While .Execute(FindText:="^13[0-9]{1,} ", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True

needs to be on one line in the Visual Basic Editor. Unfortunately, the mail
program inserts an unwanted line break.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Rebecca said:
Thanks, Doug, but I when I run the macro I get an error
message at this row

Do While .Execute(FindText:="^13[0-9]{1,} ",
MatchWildcards:=True,

What should I do now?

-----Original Message-----
Hi Rebecca,

The following macro using a Wildcard Find will convert all but the number at
the beginning of the first paragraph in the document:

Dim numrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="^13[0-9]{1,} ", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
Set numrange = Selection.Range
numrange.Start = numrange.Start + 1
numrange.End = numrange.End - 1
numrange.Text = Format(numrange.Text, "000#")
Loop
End With

To learn more about wildcards, see the article "Finding and replacing
characters using wildcards" at:

http://www.mvps.org/word/FAQs/General/UsingWildcards.htm

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Rebecca said:
Greetings.

I am using MS WORD 2002 (Office XP), and I would like to
do the following. I have many paragraphs that are headed
by numbers, such as

12 blah, blah
2 blah, blah
222 blah, blah
1354 blah, blah
43 blah, blah and so on.

I want to sort these paragraphs, but I will have to put
three zeros before the paragraphs with one digit numbers,
two zeros before the paragraphs with two digit numbers,
one zero before the paragraphs with three digit numbers,
and no zeros before the paragraphs with four digit numbers
(the largest numbers), so the result should look as
follows:

0012 blah, blah
0002 blah, blah
0222 blah, blah
1354 blah, blah
0043 blah, blah and so on.

How can this be done (hopefully in search and replace),
but if a macro is needed could you please explain in very
easy English? Thanks a million.


.
 
R

Rebecca

Thanks, Doug, the wrap problem has been solved, but
paragraphs with only one digit are not affected when the
macro is run. E.g., after running the macro I get

1 blah, blay
0033 blah, blah
5 blah, blah
0777 blah, blah and so on.

Why don't the single digits (1 and 5, above) end up with
three zeros in front of them?
-----Original Message-----
Hi Rebecca,

The whole of

Do While .Execute(FindText:="^13[0-9]{1,} ", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True

needs to be on one line in the Visual Basic Editor. Unfortunately, the mail
program inserts an unwanted line break.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Rebecca said:
Thanks, Doug, but I when I run the macro I get an error
message at this row

Do While .Execute(FindText:="^13[0-9]{1,} ",
MatchWildcards:=True,

What should I do now?

-----Original Message-----
Hi Rebecca,

The following macro using a Wildcard Find will convert all but the number at
the beginning of the first paragraph in the document:

Dim numrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="^13[0-9]{1,} ", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
Set numrange = Selection.Range
numrange.Start = numrange.Start + 1
numrange.End = numrange.End - 1
numrange.Text = Format (numrange.Text, "000#")
Loop
End With

To learn more about wildcards, see the article "Finding and replacing
characters using wildcards" at:
http://www.mvps.org/word/FAQs/General/UsingWildcards.htm
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid
consulting
basis.
Hope this helps
Doug Robbins - Word MVP
Greetings.

I am using MS WORD 2002 (Office XP), and I would like to
do the following. I have many paragraphs that are headed
by numbers, such as

12 blah, blah
2 blah, blah
222 blah, blah
1354 blah, blah
43 blah, blah and so on.

I want to sort these paragraphs, but I will have to put
three zeros before the paragraphs with one digit numbers,
two zeros before the paragraphs with two digit numbers,
one zero before the paragraphs with three digit numbers,
and no zeros before the paragraphs with four digit numbers
(the largest numbers), so the result should look as
follows:

0012 blah, blah
0002 blah, blah
0222 blah, blah
1354 blah, blah
0043 blah, blah and so on.

How can this be done (hopefully in search and replace),
but if a macro is needed could you please explain in very
easy English? Thanks a million.


.


.
 
D

Doug Robbins - Word MVP

Hi Rebecca,

As mentioned in my original post, it will not reformat the number in the
first paragraph in the document. The reason for that is that the macro is
searching for an end of paragraph mark ¶ followed by 1 or more numbers
followed by a space. If you can be sure that the only numbers in your
document are the ones that you want to convert, you can delete the ^13 from
the code and it will then act on the first paragraph as well.

When I run the macro on

1 blah, blay¶

33 blah, blah¶

5 blah, blah¶

777 blah, blah¶

it produces

1 blah, blay¶

0033 blah, blah¶

0005 blah, blah¶

0777 blah, blah¶

Is each item a separate paragraph?

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.


Hope this helps
Doug Robbins - Word MVP
Rebecca said:
Thanks, Doug, the wrap problem has been solved, but
paragraphs with only one digit are not affected when the
macro is run. E.g., after running the macro I get

1 blah, blay
0033 blah, blah
5 blah, blah
0777 blah, blah and so on.

Why don't the single digits (1 and 5, above) end up with
three zeros in front of them?
-----Original Message-----
Hi Rebecca,

The whole of

Do While .Execute(FindText:="^13[0-9]{1,} ", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True

needs to be on one line in the Visual Basic Editor. Unfortunately, the mail
program inserts an unwanted line break.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Rebecca said:
Thanks, Doug, but I when I run the macro I get an error
message at this row

Do While .Execute(FindText:="^13[0-9]{1,} ",
MatchWildcards:=True,

What should I do now?


-----Original Message-----
Hi Rebecca,

The following macro using a Wildcard Find will convert
all but the number at
the beginning of the first paragraph in the document:

Dim numrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="^13[0-9]{1,} ",
MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
Set numrange = Selection.Range
numrange.Start = numrange.Start + 1
numrange.End = numrange.End - 1
numrange.Text = Format (numrange.Text, "000#")
Loop
End With

To learn more about wildcards, see the article "Finding
and replacing
characters using wildcards" at:

http://www.mvps.org/word/FAQs/General/UsingWildcards.htm

Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested. Unsolicited
questions forwarded
directly to me will only be answered on a paid consulting
basis.

Hope this helps
Doug Robbins - Word MVP
Greetings.

I am using MS WORD 2002 (Office XP), and I would like to
do the following. I have many paragraphs that are
headed
by numbers, such as

12 blah, blah
2 blah, blah
222 blah, blah
1354 blah, blah
43 blah, blah and so on.

I want to sort these paragraphs, but I will have to put
three zeros before the paragraphs with one digit
numbers,
two zeros before the paragraphs with two digit numbers,
one zero before the paragraphs with three digit numbers,
and no zeros before the paragraphs with four digit
numbers
(the largest numbers), so the result should look as
follows:

0012 blah, blah
0002 blah, blah
0222 blah, blah
1354 blah, blah
0043 blah, blah and so on.

How can this be done (hopefully in search and replace),
but if a macro is needed could you please explain in
very
easy English? Thanks a million.


.


.
 
D

Doug Robbins - Word MVP

Hi Rebecca,

Not here they aren't. There must be something different about the single
digit numbers from the others. Are they followed by a tab rather than a
space? If you want to send a part of the document that contains such
numbers to me by email, I will take a look at it.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP

Yes, Doug, each is a separate paragraph, but all the
single digit paragraphs are ignored by the macro.
-----Original Message-----
Hi Rebecca,

As mentioned in my original post, it will not reformat the number in the
first paragraph in the document. The reason for that is that the macro is
searching for an end of paragraph mark ¶ followed by 1 or more numbers
followed by a space. If you can be sure that the only numbers in your
document are the ones that you want to convert, you can delete the ^13 from
the code and it will then act on the first paragraph as well.

When I run the macro on

1 blah, blay¶

33 blah, blah¶

5 blah, blah¶

777 blah, blah¶

it produces

1 blah, blay¶

0033 blah, blah¶

0005 blah, blah¶

0777 blah, blah¶

Is each item a separate paragraph?

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.


Hope this helps
Doug Robbins - Word MVP
Rebecca said:
Thanks, Doug, the wrap problem has been solved, but
paragraphs with only one digit are not affected when the
macro is run. E.g., after running the macro I get

1 blah, blay
0033 blah, blah
5 blah, blah
0777 blah, blah and so on.

Why don't the single digits (1 and 5, above) end up with
three zeros in front of them?
-----Original Message-----
Hi Rebecca,

The whole of

Do While .Execute(FindText:="^13[0-9]{1,} ", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True

needs to be on one line in the Visual Basic Editor. Unfortunately, the mail
program inserts an unwanted line break.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid
consulting
basis.
Hope this helps
Doug Robbins - Word MVP
Thanks, Doug, but I when I run the macro I get an error
message at this row

Do While .Execute(FindText:="^13[0-9]{1,} ",
MatchWildcards:=True,

What should I do now?


-----Original Message-----
Hi Rebecca,

The following macro using a Wildcard Find will convert
all but the number at
the beginning of the first paragraph in the document:

Dim numrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="^13[0-9]{1,} ",
MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
Set numrange = Selection.Range
numrange.Start = numrange.Start + 1
numrange.End = numrange.End - 1
numrange.Text = Format (numrange.Text, "000#")
Loop
End With

To learn more about wildcards, see the article "Finding
and replacing
characters using wildcards" at:
http://www.mvps.org/word/FAQs/General/UsingWildcards.htm
Please post any further questions or followup to the
newsgroups for the
benefit of others who may be interested. Unsolicited
questions forwarded
directly to me will only be answered on a paid consulting
basis.

Hope this helps
Doug Robbins - Word MVP
Greetings.

I am using MS WORD 2002 (Office XP), and I would like to
do the following. I have many paragraphs that are
headed
by numbers, such as

12 blah, blah
2 blah, blah
222 blah, blah
1354 blah, blah
43 blah, blah and so on.

I want to sort these paragraphs, but I will have
to
put
three zeros before the paragraphs with one digit
numbers,
two zeros before the paragraphs with two digit numbers,
one zero before the paragraphs with three digit numbers,
and no zeros before the paragraphs with four digit
numbers
(the largest numbers), so the result should look as
follows:

0012 blah, blah
0002 blah, blah
0222 blah, blah
1354 blah, blah
0043 blah, blah and so on.

How can this be done (hopefully in search and replace),
but if a macro is needed could you please explain in
very
easy English? Thanks a million.


.



.


.
 

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