Sort without "the" or "a"

  • Thread starter Thread starter lilac
  • Start date Start date
L

lilac

I want to sort a list of titles, but items such as "The ABC" should be under
A not T. How do I do this?
 
Word doesn't provide a way to do this unless you either put "The" after the
title ("ABC, The") or temporarily format "The" and A" as Hidden Text, hide
them, sort, and then remove the Hidden property.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
lilac,

Manually ;-)

AFAIK, you will have to convert "The ABC" to "ABC, The" and things like "A
Nation" to "Nation, A" before sorting.

You do it with a macro. Selecti your list paragraphs and run this code:

Sub ScratchMaco()
Dim oRng As Word.Range
Dim oPar As Paragraph
Dim oRngProcess
Dim pStr As String
Set oRng = Selection.Range
For Each oPar In oRng.Paragraphs
Select Case oPar.Range.Words.First
Case "The ", "A "
pStr = ", " & Trim(oPar.Range.Words.First)
oPar.Range.Words.First.Delete
Set oRngProcess = oPar.Range
oRngProcess.Collapse wdCollapseEnd
oRngProcess.MoveEnd wdCharacter, -1
oRngProcess.InsertAfter pStr
End Select
Next
Selection.Sort
End Sub

http://www.gmayor.com/installing_macro.htm
I want to sort a list of titles, but items such as "The ABC" should
be under A not T. How do I do this?

--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

Arrogance is a weed that grows mostly on a dunghill (Arabic proverb)
 
Ms. Barnhill,

Second option very neat. Learn something new everyday. You can also do
that with nails and hammers ;-)

Sub ScratchMacoII()
Dim oRng As Word.Range
Dim oPar As Paragraph
Dim oRngProcess
Dim pStr As String
Set oRng = Selection.Range
For Each oPar In oRng.Paragraphs
Select Case oPar.Range.Words.First
Case "The ", "A "
oPar.Range.Words.First.Font.Hidden = True
oPar.Range.Shading.BackgroundPatternColorIndex = wdBrightGreen
End Select
Next
Selection.Sort
For Each oPar In oRng.Paragraphs
Select Case oPar.Range.Shading.BackgroundPatternColorIndex
Case wdBrightGreen
oPar.Range.Words.First.Font.Hidden = False
oPar.Range.Shading.BackgroundPatternColorIndex = wdAuto
End Select
Next
End Sub

***Assumes of course that no paragraphs shading is used in the original
text.

Word doesn't provide a way to do this unless you either put "The"
after the title ("ABC, The") or temporarily format "The" and A" as
Hidden Text, hide them, sort, and then remove the Hidden property.

--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

Arrogance is a weed that grows mostly on a dunghill (Arabic proverb)
 
Good point. Also, and Ms. Barnhill did say hide them, it might help to
ensure that hidden text is not displayed during the process:

Sub ScratchMacoII()
Dim bCurrentState 'Of hidden text display option
Dim oRng As Word.Range
Dim oPar As Paragraph
Dim oRngProcess
Dim pStr As String
Set oRng = Selection.Range
For Each oPar In oRng.Paragraphs
Select Case oPar.Range.Words.First
Case "The ", "A ", "An "
oPar.Range.Words.First.Font.Hidden = True
oPar.Range.Shading.BackgroundPatternColorIndex = wdBrightGreen
End Select
Next
bCurrentState = ActiveWindow.View.ShowHiddenText
ActiveWindow.View.ShowHiddenText = False
Selection.Sort
ActiveWindow.View.ShowHiddenText = bCurrentState
For Each oPar In oRng.Paragraphs
Select Case oPar.Range.Shading.BackgroundPatternColorIndex
Case wdBrightGreen
oPar.Range.Words.First.Font.Hidden = False
oPar.Range.Shading.BackgroundPatternColorIndex = wdAuto
End Select
Next
End Sub


--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

Arrogance is a weed that grows mostly on a dunghill (Arabic proverb)


Second option very neat. Learn something new everyday. You can also do
that with nails and hammers ;-)

Sub ScratchMacoII()
Dim oRng As Word.Range
Dim oPar As Paragraph
Dim oRngProcess
Dim pStr As String
Set oRng = Selection.Range
For Each oPar In oRng.Paragraphs
Select Case oPar.Range.Words.First
Case "The ", "A "
oPar.Range.Words.First.Font.Hidden = True
oPar.Range.Shading.BackgroundPatternColorIndex = wdBrightGreen
End Select
Next
Selection.Sort
For Each oPar In oRng.Paragraphs
Select Case oPar.Range.Shading.BackgroundPatternColorIndex
Case wdBrightGreen
oPar.Range.Words.First.Font.Hidden = False
oPar.Range.Shading.BackgroundPatternColorIndex = wdAuto
End Select
Next
End Sub

***Assumes of course that no paragraphs shading is used in the original
text.

Nifty macro. I suggest adding "An " to the Case list however...
 
Back
Top