Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Word 97 in Windows XP to maintain formatting | Microsoft Word Help | |||
How to put graphics on envelopes? | Microsoft Word Help | |||
Change paper size; Word changes to invalid margins | New Users | |||
Word & WordPerfect | Microsoft Word Help | |||
Dragging table column resets | Tables |