Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
colleena
 
Posts: n/a
Default Sorting table cells in word 2003 Doc

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


  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Doug Robbins - Word MVP
 
Posts: n/a
Default Sorting table cells in word 2003 Doc

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



  #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


  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Doug Robbins - Word MVP
 
Posts: n/a
Default Sorting table cells in word 2003 Doc

Sorry,

Looks like I omitted to select the final line of the code when I copied it
into the email message. Here is the complete version:

Sub sortcolumn()
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
End With
End Sub

--
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:BfLHf.38417$JT.22800@fed1read06...

"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




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


"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




  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Tony Jollans
 
Posts: n/a
Default Sorting table cells in word 2003 Doc

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




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

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






  #8   Report Post  
Posted to microsoft.public.word.docmanagement
Tony Jollans
 
Posts: n/a
Default 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








Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word should catalog misspelled words to study. rndthought Microsoft Word Help 39 May 21st 23 02:47 AM
How do I set right and left alignment on the same line in Word? Matador Page Layout 1 November 9th 05 08:32 PM
Incompatibility Between Word 2002 and 2003 Table Viewability JCS Documentation Tables 2 October 4th 05 12:42 AM
Envelope Address GR New Users 5 April 24th 05 09:48 PM
In Word, how can I see all files (*.*) in "save as"? citizen53 New Users 8 April 4th 05 04:56 PM


All times are GMT +1. The time now is 01:27 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"