Hello Paul
Thanks for the macro, it worked great.!!
After running the macro I realized that there was more data that need to be extracted. And they are in a block format.
The format of the block is below
beginning code=abc bunch of data 908+555-1212 ending code=xyz garbage data garbage data garbage data garbage data garbage data
Sample Data
===========
beginning code=abc bunch of data 908+555-1212 ending code=xyz garbage data garbage data garbage data garbage data garbage data beginning code=abc bunch of data 908+555-1212 ending code=xyz garbage data garbage data garbage data garbage data garbage data beginning code=abc bunch of data 510+555-1212 ending code=xyz garbage data garbage data garbage data garbage data garbage data beginning code=abc bunch of data 510+555-1212 ending code=xyz garbage data garbage data garbage data garbage data garbage data beginning code=abc bunch of data 510+555-1212 ending code=xyz garbage data garbage data garbage data garbage data garbage data beginning code=abc bunch of data 510+555-1212 ending code=xyz garbage data garbage data garbage data garbage data garbage data beginning code=abc bunch of data 510+555-1212 ending code=xyz garbage data garbage data garbage data garbage data garbage data beginning code=abc bunch of data 510+555-1212 ending code=xyz garbage data garbage data garbage data garbage data garbage data beginning code=abc bunch of data 510+555-1212 ending code=xyz garbage data garbage data garbage data garbage data garbage data beginning code=abc bunch of data 510+555-1212 ending code=xyz garbage data garbage data garbage data garbage data garbage data
I was able to locate the 9 digit phone number with the following code.
Code:
Do
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^?^?^?+^?^?^?-^?^?^?^?"
.Replacement.Text = """"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Cut
Windows(2).Activate
Selection.Paste
Selection.TypeParagraph
Windows(1).Activate
Loop Until Selection.Find.Found = False
what the macro should do is to start from the beginning of the file,
1) find the 9 digits number and take out that whole record into a new window
2) now the next few records are just in sequence following the 1st record, so the macro should check to see if the next records have the same number, if it finds it then it should delete THAT NUMBER and then check for the next record and so on, once
it finds a unique number then it should extract THAT RECORD AND ADD IT DOWN BELOW 1ST RECORD THAT WAS EXTRACTED IN THAT NEW WINDOW.
any help would be greatly appreciated.
Thanks a lot.