Sorting table cells in word 2003 Doc
Hi colleena,
It's probably an empty cell. See if this helps ..
Sub SortNames()
Dim OneCell As Cell, CellRange As Range
Dim SplitVariant, SplitString() As String
For Each OneCell In ActiveDocument.Tables(1).Columns(2).Cells
Set CellRange = OneCell.Range.Duplicate
CellRange.MoveEnd wdCharacter, -1
SplitVariant = Split(CellRange.Text, ",")
SplitString = SplitVariant
If UBound(SplitString) 0 Then
WordBasic.SortArray SplitString$
CellRange.Text = Join(SplitString, ",")
End If
Next
End Sub
--
Enjoy,
Tony
"colleena" wrote in message
news:dPsIf.38910$JT.35534@fed1read06...
Hi Tony
I get a error 24 when trying to run the code
at WordBasic.SortArray SplitString$
what wrong..????
"Tony Jollans" My Forename at My Surname dot com wrote in message
...
Hi colleena,
The problem with the code for your data appears to be that the Split
statement does not split at commas.
However, you may find this a bit quicker ..
Sub SortNames()
Dim OneCell As Cell, CellRange As Range
Dim SplitVariant, SplitString() As String
For Each OneCell In ActiveDocument.Tables(1).Columns(2).Cells
Set CellRange = OneCell.Range.Duplicate
CellRange.MoveEnd wdCharacter, -1
SplitVariant = Split(CellRange.Text, ",")
SplitString = SplitVariant
WordBasic.SortArray SplitString$
CellRange.Text = Join(SplitString, ",")
Next
End Sub
--
Enjoy,
Tony
"colleena" wrote in message
news:mePHf.38432$JT.25221@fed1read06...
"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
the macro work now ...but
here is and example of column 2 after sort
Gerri,Rochelle,Rein,Annmarie,Tom,Shantaya,Cynthia, Samantha,Janice,Monica
as you can see "cynthia should be first is the cell other cells wrong
too.....
wre close....
thanks
|