Thread: Sort Question
View Single Post
  #2   Report Post  
Jay Freedman
 
Posts: n/a
Default

Hi Rob,

First, make sure that there's a paragraph mark (not a manual line break) at
the end of each line within the cell -- the sort function depends on this.
If you can sort the cell manually, then you're OK with this.

Put the following macro into a template, using the instructions at
http://www.gmayor.com/installing_macro.htm if needed. You didn't say which
column of the table you need to sort -- change the (3) to the correct column
number.

Sub SortWithinCells()
' separately sort the contents of each cell
' in a specific column of a table
Dim oRow As Row
Dim oRg As Range

If Not Selection.Information(wdWithInTable) Then
MsgBox "Please put the cursor in the table" _
& vbCr & "and restart the macro"
Exit Sub
End If

For Each oRow In Selection.Tables(1).Rows
' sort the contents of the cell in column 3
Set oRg = oRow.Cells(3).Range
oRg.MoveEnd wdCharacter, -1
oRg.Sort
Next oRow
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

RFJ wrote:
I have a table of multiple rows and columns, In each cell of one
column are multiple text entries (each entry on a new line).

What I want to do is to be able sort the entries in each cell (of
just this one column) so that they are in alpha order within each
cell.

I can do it manually (but there are over sixty of them - and the
table keeps changing ) so I then have to find any cells that have
changed and re-sort.

Is there a way I can do it in a more automated and less error prone
way.

TIA

Rob