Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
Campbell1555 Campbell1555 is offline
external usenet poster
 
Posts: 2
Default Can Word sort a table by column rather than row?

I have a multipage list that I need to put into a word table. When I put it
in, it sorts it alpha by row, not by column. Is there any way to get Word to
do this other than manually placing it by column? Any workarounds suggested?

Thanks for your input.
--
Cynthia
  #2   Report Post  
Posted to microsoft.public.word.tables
Suzanne S. Barnhill Suzanne S. Barnhill is offline
external usenet poster
 
Posts: 33,624
Default Can Word sort a table by column rather than row?

There are two ways to approach this.

1. Use newspaper-style columns instead of a table.

2. Use newspaper-style columns *and* a (single-column) table.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

"Campbell1555" wrote in message
...
I have a multipage list that I need to put into a word table. When I put

it
in, it sorts it alpha by row, not by column. Is there any way to get Word

to
do this other than manually placing it by column? Any workarounds

suggested?

Thanks for your input.
--
Cynthia


  #3   Report Post  
Posted to microsoft.public.word.tables
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 171
Default Can Word sort a table by column rather than row?

Cynthia,

The following macros should be able to sort your table as you desi

Option Explicit
Dim pCell1 As Word.Cell
Dim pCell2 As Word.Cell
Sub TableSorter()
Dim i As Long
Dim j As Long
Dim k As Long
Dim pTmpDoc As Word.Document
Dim pTmpTable As Table
Dim oRng As Word.Range
Dim SourceTable As Table
Set SourceTable = Selection.Tables(1)
i = SourceTable.Range.Cells.Count
'Insert a temporary 1 column/multi-row table in a temporary document
Set pTmpDoc = Documents.Add(Visible:=False)
Set pTmpTable = pTmpDoc.Tables.Add(Range:=pTmpDoc.Content, _
NumRows:=i, NumColumns:=1)
'Fill oTmpTable with contents of the table to be sorted
TableFillAndRefill SourceTable, pTmpTable
'Sort
pTmpTable.Sort
'Redefine source table contents based on sort
If MsgBox("Do you want to sort left to right\top to bottom?", _
vbYesNo, "Sort Order") = vbYes Then
TableFillAndRefill pTmpTable, SourceTable
Else
If MsgBox("The table will be sorted top to bottom\left to right", _
vbOKCancel, "Sort Order") = vbOK Then
With SourceTable
For i = 1 To .Range.Columns.Count
For j = 1 To .Range.Rows.Count
k = k + 1
Set oRng = pTmpTable.Cell(k, 1).Range
.Cell(j, i).Range.Text = Left(oRng.Text, Len(oRng.Text) - 2)
Next j
Next i
End With
End If
End If
'Clean up.
pTmpDoc.Close SaveChanges:=False
Set oRng = Nothing
End Sub
Sub TableFillAndRefill(pTable1 As Table, pTable2 As Table)
Set pCell1 = pTable1.Cell(1, 1)
Set pCell2 = pTable2.Cell(1, 1)
Do
pCell2.Range = Left$(pCell1.Range, Len(pCell1.Range) - 2)
Set pCell1 = pCell1.Next
Set pCell2 = pCell2.Next
Loop Until pCell1 Is Nothing
End Sub


Suzanne S. Barnhill wrote:
There are two ways to approach this.

1. Use newspaper-style columns instead of a table.

2. Use newspaper-style columns *and* a (single-column) table.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

"Campbell1555" wrote in message
...
I have a multipage list that I need to put into a word table. When I put

it
in, it sorts it alpha by row, not by column. Is there any way to get Word

to
do this other than manually placing it by column? Any workarounds

suggested?

Thanks for your input.
--
Cynthia


  #4   Report Post  
Posted to microsoft.public.word.tables
Campbell1555 Campbell1555 is offline
external usenet poster
 
Posts: 2
Default Can Word sort a table by column rather than row?

Could you please give me directions on how to implement these macros? Do I
create the table and insert the text and then run the macros? It appears
that there are two separate macros. Do I run them together or separate?

Thanks for your patience.

Cynthia
--
Cynthia


"Greg Maxey" wrote:

Cynthia,

The following macros should be able to sort your table as you desi

Option Explicit
Dim pCell1 As Word.Cell
Dim pCell2 As Word.Cell
Sub TableSorter()
Dim i As Long
Dim j As Long
Dim k As Long
Dim pTmpDoc As Word.Document
Dim pTmpTable As Table
Dim oRng As Word.Range
Dim SourceTable As Table
Set SourceTable = Selection.Tables(1)
i = SourceTable.Range.Cells.Count
'Insert a temporary 1 column/multi-row table in a temporary document
Set pTmpDoc = Documents.Add(Visible:=False)
Set pTmpTable = pTmpDoc.Tables.Add(Range:=pTmpDoc.Content, _
NumRows:=i, NumColumns:=1)
'Fill oTmpTable with contents of the table to be sorted
TableFillAndRefill SourceTable, pTmpTable
'Sort
pTmpTable.Sort
'Redefine source table contents based on sort
If MsgBox("Do you want to sort left to right\top to bottom?", _
vbYesNo, "Sort Order") = vbYes Then
TableFillAndRefill pTmpTable, SourceTable
Else
If MsgBox("The table will be sorted top to bottom\left to right", _
vbOKCancel, "Sort Order") = vbOK Then
With SourceTable
For i = 1 To .Range.Columns.Count
For j = 1 To .Range.Rows.Count
k = k + 1
Set oRng = pTmpTable.Cell(k, 1).Range
.Cell(j, i).Range.Text = Left(oRng.Text, Len(oRng.Text) - 2)
Next j
Next i
End With
End If
End If
'Clean up.
pTmpDoc.Close SaveChanges:=False
Set oRng = Nothing
End Sub
Sub TableFillAndRefill(pTable1 As Table, pTable2 As Table)
Set pCell1 = pTable1.Cell(1, 1)
Set pCell2 = pTable2.Cell(1, 1)
Do
pCell2.Range = Left$(pCell1.Range, Len(pCell1.Range) - 2)
Set pCell1 = pCell1.Next
Set pCell2 = pCell2.Next
Loop Until pCell1 Is Nothing
End Sub


Suzanne S. Barnhill wrote:
There are two ways to approach this.

1. Use newspaper-style columns instead of a table.

2. Use newspaper-style columns *and* a (single-column) table.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

"Campbell1555" wrote in message
...
I have a multipage list that I need to put into a word table. When I put

it
in, it sorts it alpha by row, not by column. Is there any way to get Word

to
do this other than manually placing it by column? Any workarounds

suggested?

Thanks for your input.
--
Cynthia



  #5   Report Post  
Posted to microsoft.public.word.tables
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 285
Default Can Word sort a table by column rather than row?

Cynthia,

There are two procedures. The first calls the second. Just copy the whole
shebang into your VB editor and run TableSorter.

See:
http://www.gmayor.com/installing_macro.htm


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

"Campbell1555" wrote in message
...
Could you please give me directions on how to implement these macros? Do
I
create the table and insert the text and then run the macros? It appears
that there are two separate macros. Do I run them together or separate?

Thanks for your patience.

Cynthia
--
Cynthia


"Greg Maxey" wrote:

Cynthia,

The following macros should be able to sort your table as you desi

Option Explicit
Dim pCell1 As Word.Cell
Dim pCell2 As Word.Cell
Sub TableSorter()
Dim i As Long
Dim j As Long
Dim k As Long
Dim pTmpDoc As Word.Document
Dim pTmpTable As Table
Dim oRng As Word.Range
Dim SourceTable As Table
Set SourceTable = Selection.Tables(1)
i = SourceTable.Range.Cells.Count
'Insert a temporary 1 column/multi-row table in a temporary document
Set pTmpDoc = Documents.Add(Visible:=False)
Set pTmpTable = pTmpDoc.Tables.Add(Range:=pTmpDoc.Content, _
NumRows:=i, NumColumns:=1)
'Fill oTmpTable with contents of the table to be sorted
TableFillAndRefill SourceTable, pTmpTable
'Sort
pTmpTable.Sort
'Redefine source table contents based on sort
If MsgBox("Do you want to sort left to right\top to bottom?", _
vbYesNo, "Sort Order") = vbYes Then
TableFillAndRefill pTmpTable, SourceTable
Else
If MsgBox("The table will be sorted top to bottom\left to right", _
vbOKCancel, "Sort Order") = vbOK Then
With SourceTable
For i = 1 To .Range.Columns.Count
For j = 1 To .Range.Rows.Count
k = k + 1
Set oRng = pTmpTable.Cell(k, 1).Range
.Cell(j, i).Range.Text = Left(oRng.Text, Len(oRng.Text) - 2)
Next j
Next i
End With
End If
End If
'Clean up.
pTmpDoc.Close SaveChanges:=False
Set oRng = Nothing
End Sub
Sub TableFillAndRefill(pTable1 As Table, pTable2 As Table)
Set pCell1 = pTable1.Cell(1, 1)
Set pCell2 = pTable2.Cell(1, 1)
Do
pCell2.Range = Left$(pCell1.Range, Len(pCell1.Range) - 2)
Set pCell1 = pCell1.Next
Set pCell2 = pCell2.Next
Loop Until pCell1 Is Nothing
End Sub


Suzanne S. Barnhill wrote:
There are two ways to approach this.

1. Use newspaper-style columns instead of a table.

2. Use newspaper-style columns *and* a (single-column) table.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so
all may benefit.

"Campbell1555" wrote in
message
...
I have a multipage list that I need to put into a word table. When I
put
it
in, it sorts it alpha by row, not by column. Is there any way to get
Word
to
do this other than manually placing it by column? Any workarounds
suggested?

Thanks for your input.
--
Cynthia







  #6   Report Post  
Posted to microsoft.public.word.tables
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 285
Default Can Word sort a table by column rather than row?

I just added a template AddIn to my website that you can use:
http://gregmaxey.mvps.org/Table_Sorter.htm


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Campbell1555 wrote:
Could you please give me directions on how to implement these macros?
Do I create the table and insert the text and then run the macros?
It appears that there are two separate macros. Do I run them
together or separate?

Thanks for your patience.

Cynthia

Cynthia,

The following macros should be able to sort your table as you desi

Option Explicit
Dim pCell1 As Word.Cell
Dim pCell2 As Word.Cell
Sub TableSorter()
Dim i As Long
Dim j As Long
Dim k As Long
Dim pTmpDoc As Word.Document
Dim pTmpTable As Table
Dim oRng As Word.Range
Dim SourceTable As Table
Set SourceTable = Selection.Tables(1)
i = SourceTable.Range.Cells.Count
'Insert a temporary 1 column/multi-row table in a temporary document
Set pTmpDoc = Documents.Add(Visible:=False)
Set pTmpTable = pTmpDoc.Tables.Add(Range:=pTmpDoc.Content, _
NumRows:=i, NumColumns:=1)
'Fill oTmpTable with contents of the table to be sorted
TableFillAndRefill SourceTable, pTmpTable
'Sort
pTmpTable.Sort
'Redefine source table contents based on sort
If MsgBox("Do you want to sort left to right\top to bottom?", _
vbYesNo, "Sort Order") = vbYes Then
TableFillAndRefill pTmpTable, SourceTable
Else
If MsgBox("The table will be sorted top to bottom\left to right", _
vbOKCancel, "Sort Order") = vbOK Then
With SourceTable
For i = 1 To .Range.Columns.Count
For j = 1 To .Range.Rows.Count
k = k + 1
Set oRng = pTmpTable.Cell(k, 1).Range
.Cell(j, i).Range.Text = Left(oRng.Text, Len(oRng.Text) -
2) Next j
Next i
End With
End If
End If
'Clean up.
pTmpDoc.Close SaveChanges:=False
Set oRng = Nothing
End Sub
Sub TableFillAndRefill(pTable1 As Table, pTable2 As Table)
Set pCell1 = pTable1.Cell(1, 1)
Set pCell2 = pTable2.Cell(1, 1)
Do
pCell2.Range = Left$(pCell1.Range, Len(pCell1.Range) - 2)
Set pCell1 = pCell1.Next
Set pCell2 = pCell2.Next
Loop Until pCell1 Is Nothing
End Sub


Suzanne S. Barnhill wrote:
There are two ways to approach this.

1. Use newspaper-style columns instead of a table.

2. Use newspaper-style columns *and* a (single-column) table.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

"Campbell1555" wrote in
message ...
I have a multipage list that I need to put into a word table.
When I put it in, it sorts it alpha by row, not by column. Is
there any way to get Word to do this other than manually placing
it by column? Any workarounds suggested?

Thanks for your input.
--
Cynthia



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 97 in Windows XP to maintain formatting Charlie''s Word VBA questions Microsoft Word Help 22 May 20th 23 08:51 PM
How to put graphics on envelopes? Steve Koenig Microsoft Word Help 21 April 29th 23 02:47 AM
Change paper size; Word changes to invalid margins OhioTech New Users 10 July 6th 06 02:00 PM
Word & WordPerfect MrsMac Microsoft Word Help 5 June 10th 06 03:14 AM
Dragging table column resets Sedonakids Tables 0 January 12th 05 02:11 AM


All times are GMT +1. The time now is 05:23 PM.

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"