View Single Post
  #3   Report Post  
Posted to microsoft.public.word.docmanagement
colleena
 
Posts: n/a
Default Sorting table cells in word 2003 Doc


"Doug Robbins - Word MVP" wrote in message
...
The following code in a macro would sort the contents of each cell in the
second column of the first table in the document. It assumes that the
content of the cell in the first row is not to be sorted.

Dim i As Long, Srange As Range, sarray As Variant
Dim source As Document, target As Document, j As Long
Dim sstring As String, rrange As Range
Set source = ActiveDocument
With source.Tables(1).Columns(2)
For i = 2 To .Cells.Count
Set Srange = .Cells(i).Range
Srange.End = Srange.End - 1
Srange = Srange & ","
sarray = Split(Srange)
Set target = Documents.Add
For j = 0 To UBound(sarray)
target.Range.InsertAfter sarray(j) & vbCr
Next j
target.Content.Sort SortOrder:=wdSortOrderAscending
target.Paragraphs(1).Range.Delete
sstring = ""
For j = 1 To target.Range.Paragraphs.Count
Set rrange = target.Range.Paragraphs(j).Range
rrange.End = rrange.End - 1
sstring = sstring & rrange & " "
Next j
sstring = Left(sstring, Len(sstring) - 2)
Srange = sstring
target.Close wdDoNotSaveChanges
Next i


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"colleena" wrote in message
news:lEGHf.38393$JT.35549@fed1read06...
I have a table with 2 columns..

colum 1 contains an aphpa-number ( A503 ) Cust Nr.

colum 2 contains peoples First names seperated by commas some cells have
as many as 10 first names
orher cells might only 1 first name. sorting the table by colum 1 No
problem.....now I need to alpha sort the contents of cell 2. big
problem...any Ideas....

Thanks in advance


I have a Compile problem with code ???
what am I doing wrong Inamed the macro sortcolum