This turned out to be a lot more than 'fine-tuning' because there's no
way to know in advance what you've selected. It could be the whole
cell including the cell marker, the text of the whole cell but NOT
including the cell marker, some at the beginning, some in the middle,
or some at the end. Because of Word's quirkiness (some might call it
perverseness), each of these cases has to be handled differently.
Sub SortInOneCell()
Dim oRg As Range
Dim rgStart As Long, rgEnd As Long
If Not Selection.Information(wdWithInTable) Then
MsgBox "The cursor isn't in a table."
Exit Sub
End If
If Selection.Cells.Count > 1 Then
MsgBox "Keep the selection within one cell."
Exit Sub
End If
With Selection
If .Range.Start > .Cells(1).Range.Start Then
' add a para mark and exclude it
.InsertBefore vbCr
.MoveStart unit:=wdCharacter, Count:=1
End If
If (Right$(.Text, 2) <> ", ") And _
(.Range.End < .Cells(1).Range.End - 1) Then
' if end of sel isn't at end of item or
' end of cell, extend it
.MoveEndUntil cset:=" "
.MoveEndWhile cset:=" "
Set oRg = .Range
Else
Set oRg = .Range
If (.Range.End = .Cells(1).Range.End) Then
' if sel includes cell marker, exclude it
oRg.MoveEnd unit:=wdCharacter, Count:=-1
End If
End If
End With
With oRg.Find
.Text = ", "
.Replacement.Text = "^p"
.Wrap = wdFindStop
.Execute Replace:=wdReplaceAll
End With
' the sort will collapse the range, so save it
rgStart = oRg.Start
rgEnd = oRg.End
' avoid error 'no items found to sort'
On Error Resume Next
oRg.Sort
On Error GoTo 0
' restore original range
Set oRg = ActiveDocument.Range(Start:=rgStart, End:=rgEnd)
' if any empty para, it sorts to the top
If oRg.Characters.First = vbCr Then
oRg.Characters.First.Delete
End If
With oRg.Find
.Text = "^p"
.Replacement.Text = ", "
.Wrap = wdFindStop
.Execute Replace:=wdReplaceAll
End With
With oRg
If (.Start > .Cells(1).Range.Start) Then
' remove para mark inserted before sel
If .Characters.First.Previous = vbCr Then
.Characters.First.Previous.Delete
End If
End If
End With
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP
Wow, that's great. Sorry to be fussy though but I really do need it to work
just on 'selected text' as I have some cells which have a few words at the
start that I don't want sorted.
Can you fine-tune once more?

--
Thanks.
CJSnet
(Remove TEETH to reply by e-mail.)