PDA

View Full Version : Paragraphs sorting in word2003



jsanraj
05-20-2011, 08:35 AM
Hi friends,

I have to sort the paragraphs in the word document based on the word which is surrounded by tag <SNM> in each paragraph. How this can be achieved in Word 2003.

example:

AJAY <SNM>NEHRA</SNM>, MD, FACS, Department of Urology, Mayo Clinic College of Medicine, Mayo Clinic, Rochester, Minnesota
ANDRE T. <SNM>GUAY</SNM>, MD, Center For Sexual Function/Endocrinology, Lahey Clinic, Peabody, Massachusetts
ARTHUR L. <SNM>BURNETT</SNM>, MD, MBA</bold>, Professor of Urology and Director, Division of Sexual Medicine, Department of Urology, The James Buchanan Brady Urological Institute, Johns Hopkins Medical Institutions, Johns Hopkins Hospital, Baltimore, Maryland
CLARISSE <SNM>MAZZOLA</SNM>, MD</bold>, Sexual &amp; Reproductive Medicine Program, Division Of Urology, Memorial Sloan Kettering Cancer Center, New York, New York
CRAIG F. <SNM>DONATUCCI</SNM>, MD, Professor of Surgery, Division of Urology, Department of Surgery, Duke University Medical Center, Durham, North Carolina
CULLEY C. <SNM>CARSON</SNM> III, MD, FACS
CULLEY C. <SNM>CARSON</SNM> III, MD, Rhodes Distinguished Professor of Urology, Chief of Urology, University of North Carolina at Chapel Hill, Chapel Hill, North Carolina
CULLEY C. <SNM>CARSON</SNM>, III, MD, FACS, Rhodes Distinguished Professor, Chief of Urology, Division of Urologic Surgery, Department of Surgery, University of North Carolina, Chapel Hill, North Carolina

Thanks in advance

Frosty
05-20-2011, 11:58 AM
Why don't you do a find/replace on "<SNM>" and "</SNM>" and replace that with a pipe (|) character...

Then use Convert Text to Table based on the pipe character.

From there, once the text is in a table... the sorting should be fairly straight-forward.

To do this in code would require loading all of the data into an array and using the .SortArray method.

To turn the find/replace procedure into code simply requires you recording the macro.

As an aside-- I think you should use fake data, instead of posting real people's personal data on a website.

If I were Craig F. Donatucci, I'd be irritated to have my personal info dessiminated on a website by someone simply trying to manipulate my data.

gmaxey
05-20-2011, 03:28 PM
Try:

Select the list of names (each list item must be a separate paragraph).

Sub ScratchMacro()
'A quick macro scratch pad created by Greg Maxey
Dim oRng As Word.Range
Set oRng = Selection.Range
With oRng.Find
.Text = "SNM"
.Replacement.Text = "|"
.Execute Replace:=wdReplaceAll
End With
Set oRng = Selection.Range
oRng.Sort FieldNumber:=2
Set oRng = Selection.Range
With oRng.Find
.Text = "|"
.Replacement.Text = "SNM"
.Execute Replace:=wdReplaceAll
End With
Msgbox "If I were Craig or anyone else on your list, I would be irritated as well."
End Sub



Hi friends,

I have to sort the paragraphs in the word document based on the word which is surrounded by tag <SNM> in each paragraph. How this can be achieved in Word 2003.

example:

AJAY <SNM>NEHRA</SNM>, MD, FACS, Department of Urology, Mayo Clinic College of Medicine, Mayo Clinic, Rochester, Minnesota
ANDRE T. <SNM>GUAY</SNM>, MD, Center For Sexual Function/Endocrinology, Lahey Clinic, Peabody, Massachusetts
ARTHUR L. <SNM>BURNETT</SNM>, MD, MBA</bold>, Professor of Urology and Director, Division of Sexual Medicine, Department of Urology, The James Buchanan Brady Urological Institute, Johns Hopkins Medical Institutions, Johns Hopkins Hospital, Baltimore, Maryland
CLARISSE <SNM>MAZZOLA</SNM>, MD</bold>, Sexual &amp; Reproductive Medicine Program, Division Of Urology, Memorial Sloan Kettering Cancer Center, New York, New York
CRAIG F. <SNM>DONATUCCI</SNM>, MD, Professor of Surgery, Division of Urology, Department of Surgery, Duke University Medical Center, Durham, North Carolina
CULLEY C. <SNM>CARSON</SNM> III, MD, FACS
CULLEY C. <SNM>CARSON</SNM> III, MD, Rhodes Distinguished Professor of Urology, Chief of Urology, University of North Carolina at Chapel Hill, Chapel Hill, North Carolina
CULLEY C. <SNM>CARSON</SNM>, III, MD, FACS, Rhodes Distinguished Professor, Chief of Urology, Division of Urologic Surgery, Department of Surgery, University of North Carolina, Chapel Hill, North Carolina

Thanks in advance

macropod
05-20-2011, 09:08 PM
You could also use a wildcard Find/Replace to put the Surnames first, then do the sorting. For example:
Find = (^13)([!\<]{1,})(\<SNM\>)([!\<]{1,})(\</SNM\>)
Replace = \1\4, \2
Note: the above replace code is intended to delete the SNM tags. You could keep them with:
Replace = \1\3\4\5 \2