Help!

Sort without "the" or "a"

 
  

Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Document Management RSS
Next:  Form Fill-In Field  
Author Message
lilac
External


Since: Nov 04, 2009
Posts: 1



PostPosted: Wed Nov 04, 2009 3:58 pm    Post subject: Sort without "the" or "a"
Archived from groups: microsoft>public>word>docmanagement (more info?)

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?
Back to top
Suzanne S. Barnhill
External


Since: Sep 26, 2003
Posts: 24065



PostPosted: Wed Nov 04, 2009 6:25 pm    Post subject: Re: Sort without "the" or "a" [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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" <lilac.TakeThisOut@discussions.microsoft.com> wrote in message
news:EC52C6D3-F40D-4856-8E01-64C096ED96C4@microsoft.com...
>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?
Back to top
Greg Maxey
External


Since: Feb 01, 2009
Posts: 57



PostPosted: Wed Nov 04, 2009 7:44 pm    Post subject: Re: Sort without "the" or "a" [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

lilac,

Manually Wink

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

lilac wrote:
> 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)
Back to top
Greg Maxey
External


Since: Feb 01, 2009
Posts: 57



PostPosted: Wed Nov 04, 2009 7:51 pm    Post subject: Re: Sort without "the" or "a" [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Ms. Barnhill,

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

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.


Suzanne S. Barnhill wrote:
> 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.
>
>
> "lilac" <lilac.TakeThisOut@discussions.microsoft.com> wrote in message
> news:EC52C6D3-F40D-4856-8E01-64C096ED96C4@microsoft.com...
>> 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)
Back to top
Opinicus
External


Since: Jun 17, 2009
Posts: 3



PostPosted: Thu Nov 05, 2009 1:10 am    Post subject: Re: Sort without "the" or "a" [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Wed, 4 Nov 2009 19:51:10 -0500, "Greg Maxey"
<gmaxey DeleteThis @mIKEvICTORpAPAsIERRA.oSCARrOMEOgOLF> wrote:

> Second option very neat. Learn something new everyday. You can also do
> that with nails and hammers Wink
>
> 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...

--
Bob
http://www.kanyak.com
Back to top
Greg Maxey
External


Since: Feb 01, 2009
Posts: 57



PostPosted: Thu Nov 05, 2009 6:55 am    Post subject: Re: Sort without "the" or "a" [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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)


"Opinicus" <gezgin.DeleteThis@spamcop.net.which.is.not.invalid> wrote in message
news:llp4f5d5toq9pjimferin2ebu8hqehh94u@4ax.com...
On Wed, 4 Nov 2009 19:51:10 -0500, "Greg Maxey"
<gmaxey.DeleteThis@mIKEvICTORpAPAsIERRA.oSCARrOMEOgOLF> wrote:

> Second option very neat. Learn something new everyday. You can also do
> that with nails and hammers Wink
>
> 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...

--
Bob
http://www.kanyak.com
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Document Management All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum