alphabetizing by first letter of exisitng list in Word 2007

  • Thread starter Thread starter jakson
  • Start date Start date
J

jakson

Is there a way to cause an existing list to be organized by the first letter of
each line of the list?
 
Probably overkill for the described sort, which can easily be accomplished
by a simple sort, as Peter precisely described in his previous answer.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
Is there some reason, other that your particullarily annoying habit of
bloating your post count, that you chose not to let the OP decide if the
method is overkill or not?
 
Well, we may never know which method the OP chooses, but I'm just curious
why you think anyone would take the trouble to copy and install a macro for
such a simple and straightforward task. To me this seems like installing a
macro to center text or apply a specific font. When the required tool is
available on a menu or the Ribbon, why would I choose to use a macro
instead?

I'm asking this question seriously. If you were in this situation, with a
document full of paragraphs to be sorted, would you write a macro to do it
or just pull down Table | Sort or click the Sort button on the Home tab?

Note that I'm not denigrating macros or implying that they are not massively
useful (for example, I suspect a macro would be needed to assign bookmarks
to copied form fields, per another question here). I just don't understand
why you think anyone would prefer a macro for this specific task.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
Where in my post did I say "I think you should take the trouble to ..." I
did not say to the OP that I think you should do this over something else,
nor do I care if they do or do not.

As you took such pains to point out, Mr. Daniels had already provided a
perfectly sensible and perhaps preferable method of performing the specific
task. Like you, I did not denigrate his method. In fact, until now, I
didn't say anything about it at all. I simply provided a method for the OP
to consider and take or leave at will.
I'm asking this question seriously. If you were in this situation, with a
document full of paragraphs to be sorted, would you write a macro to do it
or just pull down Table | Sort or click the Sort button on the Home tab?

No. I would not write a macro to do it because I have already written one
that I use. I have it assigned to shortcut and it is available at the link
I posted free for you or anyone else to use as you or they see fit. I wrote
and use the macro because, while I do not normally write jumbled up
paragraphs and then sort them, when I want to sort items in a list I want to
make sure that duplicate items are not present in the final list list.

.....
 
Your macro is thus a useful tool for doing something other than what
OP requested -- and if you had pointed out that extra feature in your
first message, you likely would have gotten a thank you rather than a
puzzlement in response.
 
Mr. Daniels,

Thank you for this enlightening post.

I am sure that the OP is similiarly tickled pink and feeling well treated
and welcome in this group by your poke in the eye when you could just as
easily and gracefully overlooked his obviously erroneous double post.
 
Please excuse the developing low intensity fracas in the other branches of
this thread.

Mr. Daniels is correct in pointing out that the macro solution that I
provided may have an undesirable effect on your list. As I attempted to
illustrate and perhaps it was clear to you, the macro will automatically
remove duplicated entries in your list. This could be useful if you have
haphazardly created a long list of names or other items and now want to sort
and streamline the list.

The following is a revised version of the basic macro which gives you the
option to a) sort the list, b) sort and delete duplicates, or c)sort, review
then delete or keep duplicates. Note: a) has no practical value over the
UI method Mr. Daniels initially provided.

Sub SortAndRemoveDuplicatesFromList()
Dim oPars As Paragraphs
Dim oPar As Paragraph
Dim myCol As New Collection
Dim bView As Boolean
bView = False
Set oPars = Selection.Paragraphs
'Perform the sort
If oPars.Count > 1 Then
Selection.Sort SortOrder:=wdSortOrderAscending
Else
MsgBox "There is no valid selection to sort"
Exit Sub
End If
'Remove duplicates
If MsgBox("Do you want to remove duplicate entries from the list?", _
vbQuestion + vbYesNo, "Remove Duplicates") = vbYes Then
If MsgBox("Do you want to view duplicate entries before deleting", _
vbQuestion + vbYesNo, "View Duplicates") = vbYes Then
bView = True
End If
For Each oPar In ActiveDocument.Range.Paragraphs
On Error Resume Next
myCol.Add oPar.Range.Text, oPar.Range.Text
If Err.Number = 457 Then
If bView Then
oPar.Range.Select
If MsgBox("Do you want to delete this duplicate instance?",
vbQuestion + vbYesNo, _
"Duplicate Item") = vbYes Then
oPar.Range.Delete
End If
Else
oPar.Range.Delete
End If
End If
Next
End If
End Sub
 
Back
Top