Sort ignoring "The" and "A"

B

Bob

My table is list of book titles and I wish to sort aphabetically
ignoring articles "The" and "A" so that a title such as "The Zebra" is
sorted as letter Z. Is there a function in Word to permit ignoring
articles?
TIA
Bob
 
G

Greg Maxey

Bob,

AFAIK it can't be done without some manipulation of of the table.
Basically, you would need to strip off the first word of the list if it
was an "A" or the word "The," then sort the list, and finally add the
word "A" or "The" back where appropriate. I cobbled together a macro
which does this automatically for a list of title in the first column
of a table. The testing was very limited so it may not work for you:

Sub Test()
Dim oCell As Cell
Dim i As Long
Dim j As Long
With Selection.Tables(1)
.Columns.Add BeforeColumn:=.Columns(1)
For i = 1 To .Rows.Count
If .Cell(i, 2).Range.Words(1) = "A " Or _
.Cell(i, 2).Range.Words(1) = "The " Then
.Cell(i, 1).Range.Text = .Cell(i, 2).Range.Words(1)
.Cell(i, 2).Range.Words(1).Delete
End If
Next
.Sort FieldNumber:="Column 2",
SortFieldType:=wdSortFieldAlphanumeric, _
SortOrder:=wdSortOrderAscending
For i = 1 To .Rows.Count
j = .Cell(i, 2).Width
.Cell(i, 1).Merge MergeTo:=.Cell(i, 2)
.Cell(i, 1).Width = j
Next
.Columns(1).Select
With Selection.Find
.Text = "^13"
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
End With
End Sub
 
G

Greg Maxey

You might also want to sort this like,

Zebra, The

Use:

Sub Test2()
Dim oCell As Cell
Dim i As Long
Dim j As Long
With Selection.Tables(1)
For i = 1 To .Rows.Count
If .Cell(i, 1).Range.Words(1) = "A " Or _
.Cell(i, 1).Range.Words(1) = "The " Then
.Cell(i, 1).Range.InsertAfter ", " & .Cell(i, 1).Range.Words(1)
.Cell(i, 1).Range.Words(1).Delete
End If
Next
.Sort FieldNumber:="Column 2",
SortFieldType:=wdSortFieldAlphanumeric, _
SortOrder:=wdSortOrderAscending
End With
End Sub
 
K

Klaus Linke

Bob said:
My table is list of book titles and I wish to sort aphabetically
ignoring articles "The" and "A" so that a title such as "The Zebra" is
sorted as letter Z. Is there a function in Word to permit ignoring
articles?
TIA
Bob


Hi Bob,

Another possibility is to format "The " and "A " and "An " as hidden text,
temporarily.
Hidden text is ignored in sorting, as long as it isn't visible on screen.

To achieve that, you could use wildcard replacements, say replace "<The> "
with "^&" and "Format > Font > Hidden" (or Ctrl+Shift+H) in "Replace with" .

Once sorted, you can select all the table and set the font to "Not hidden".

Greetings,
Klaus
 

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