Find and Replace

I

Island Girl

I have a 50 page document with names, addresses and phone numbers. The phone
numbers are not formatted as usual (for example, (954) 543-1800). Instead
they're just 10 numbers in a row (9545431800). I thought I had learned
enough from you to figure this out myself, but I'm stumbling.

Can you tell me how to change the phone numbers to this example: (954)
543-1800 with your find and replace wizardry?

Thanks so very, very much.
 
I

Island Girl

You, my teachers, will be proud to know that I figured it out. Thanks for
making that possible!!!!!
 
G

Greg Maxey

The answer depends on if the numbers are

1234567890

or

(1234567890)

Run one of the following two macors:


Option Explicit
Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Content
With oRng.Find
.Text = "[0-9]{10}"
.MatchWildcards = True
While .Execute
oRng.Text = "(" & Left(oRng.Text, 3) & ")-" & Mid(oRng.Text, 4, 3) & "-"
& Right(oRng.Text, 4)
oRng.Collapse wdCollapseEnd
Wend
End With
End Sub

Sub ScratchMacroII()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Content
With oRng.Find
.Text = "\([0-9]{10}\)"
.MatchWildcards = True
While .Execute
oRng.Text = Left(oRng.Text, 4) & ")-" & Mid(oRng.Text, 5, 3) & "-" &
Mid(oRng.Text, 8, 4)
oRng.Collapse wdCollapseEnd
Wend
End With
End Sub
 
G

Greg Maxey

Or run one of these pairs in the Find and Replace with wildcards on:

(\([0-9]{3})([0-9]{3})([0-9]{4})(\))



\1)-\2-\3





([0-9]{3})([0-9]{3})([0-9]{4})



(\1)-\2-\3
 
I

Island Girl

Thanks, Greg, for your continued support and for teaching me so much. I'm
sorry to be so late in telling you that moments after my email to the group,
my "panic" disappeared and I figured it out, using the same pairs as below.
I just can't read enough about it, and I just can't thank you and your fellow
MVPs enough!

I've found the study of wildcards--to which you have contributed so much--to
be the most fascinating and perhaps the single most helpful thing in my work.
Keep those golden nuggets coming!

Greg Maxey said:
Or run one of these pairs in the Find and Replace with wildcards on:

(\([0-9]{3})([0-9]{3})([0-9]{4})(\))



\1)-\2-\3





([0-9]{3})([0-9]{3})([0-9]{4})



(\1)-\2-\3


Island said:
I have a 50 page document with names, addresses and phone numbers.
The phone numbers are not formatted as usual (for example, (954)
543-1800). Instead they're just 10 numbers in a row (9545431800). I
thought I had learned enough from you to figure this out myself, but
I'm stumbling.

Can you tell me how to change the phone numbers to this example: (954)
543-1800 with your find and replace wizardry?

Thanks so very, very much.
 
G

Graham Mayor

For even more coverage of wildcards, see
http://www.gmayor.com/replace_using_wildcards.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Island said:
Thanks, Greg, for your continued support and for teaching me so much.
I'm sorry to be so late in telling you that moments after my email to
the group, my "panic" disappeared and I figured it out, using the
same pairs as below. I just can't read enough about it, and I just
can't thank you and your fellow MVPs enough!

I've found the study of wildcards--to which you have contributed so
much--to be the most fascinating and perhaps the single most helpful
thing in my work. Keep those golden nuggets coming!

Greg Maxey said:
Or run one of these pairs in the Find and Replace with wildcards on:

(\([0-9]{3})([0-9]{3})([0-9]{4})(\))



\1)-\2-\3





([0-9]{3})([0-9]{3})([0-9]{4})



(\1)-\2-\3


Island said:
I have a 50 page document with names, addresses and phone numbers.
The phone numbers are not formatted as usual (for example, (954)
543-1800). Instead they're just 10 numbers in a row (9545431800).
I thought I had learned enough from you to figure this out myself,
but I'm stumbling.

Can you tell me how to change the phone numbers to this example:
(954) 543-1800 with your find and replace wizardry?

Thanks so very, very much.
 
I

Island Girl

That's exactly how I finally figured it out, Graham! It's my Find & Replace
Bible. I was stumbling at first--but the answer was so very simple after
putting into place what I'd learned from your article! Can't thank you
enough!

Graham Mayor said:
For even more coverage of wildcards, see
http://www.gmayor.com/replace_using_wildcards.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Island said:
Thanks, Greg, for your continued support and for teaching me so much.
I'm sorry to be so late in telling you that moments after my email to
the group, my "panic" disappeared and I figured it out, using the
same pairs as below. I just can't read enough about it, and I just
can't thank you and your fellow MVPs enough!

I've found the study of wildcards--to which you have contributed so
much--to be the most fascinating and perhaps the single most helpful
thing in my work. Keep those golden nuggets coming!

Greg Maxey said:
Or run one of these pairs in the Find and Replace with wildcards on:

(\([0-9]{3})([0-9]{3})([0-9]{4})(\))



\1)-\2-\3





([0-9]{3})([0-9]{3})([0-9]{4})



(\1)-\2-\3


Island Girl wrote:
I have a 50 page document with names, addresses and phone numbers.
The phone numbers are not formatted as usual (for example, (954)
543-1800). Instead they're just 10 numbers in a row (9545431800).
I thought I had learned enough from you to figure this out myself,
but I'm stumbling.

Can you tell me how to change the phone numbers to this example:
(954) 543-1800 with your find and replace wizardry?

Thanks so very, very much.
 
G

Graham Mayor

You are welcome :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Island said:
That's exactly how I finally figured it out, Graham! It's my Find &
Replace Bible. I was stumbling at first--but the answer was so very
simple after putting into place what I'd learned from your article!
Can't thank you enough!

Graham Mayor said:
For even more coverage of wildcards, see
http://www.gmayor.com/replace_using_wildcards.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Island said:
Thanks, Greg, for your continued support and for teaching me so
much. I'm sorry to be so late in telling you that moments after my
email to the group, my "panic" disappeared and I figured it out,
using the same pairs as below. I just can't read enough about it,
and I just can't thank you and your fellow MVPs enough!

I've found the study of wildcards--to which you have contributed so
much--to be the most fascinating and perhaps the single most helpful
thing in my work. Keep those golden nuggets coming!

:

Or run one of these pairs in the Find and Replace with wildcards
on:

(\([0-9]{3})([0-9]{3})([0-9]{4})(\))



\1)-\2-\3





([0-9]{3})([0-9]{3})([0-9]{4})



(\1)-\2-\3


Island Girl wrote:
I have a 50 page document with names, addresses and phone numbers.
The phone numbers are not formatted as usual (for example, (954)
543-1800). Instead they're just 10 numbers in a row (9545431800).
I thought I had learned enough from you to figure this out myself,
but I'm stumbling.

Can you tell me how to change the phone numbers to this example:
(954) 543-1800 with your find and replace wizardry?

Thanks so very, very much.
 

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