WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Can Word sort a table by column rather than row?

 
   Home -> Office -> Tables RSS
Next:  words splitting up in tables, word wrap  
Author Message
Campbell1555

External


Since: Dec 08, 2006
Posts: 2



(Msg. 1) Posted: Fri Dec 08, 2006 8:08 am
Post subject: Can Word sort a table by column rather than row?
Archived from groups: microsoft>public>word>tables (more info?)

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
Back to top
Login to vote
Greg Maxey

External


Since: May 08, 2006
Posts: 66



(Msg. 2) Posted: Fri Dec 08, 2006 9:48 am
Post subject: Re: Can Word sort a table by column rather than row? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Cynthia,

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

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" <Campbell1555 RemoveThis @discussions.microsoft.com> wrote in message
> news:8346A9B4-C644-4066-B0C2-2F7736D33F51@microsoft.com...
> > 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
Back to top
Login to vote
Suzanne S. Barnhill

External


Since: Sep 26, 2003
Posts: 18967



(Msg. 3) Posted: Fri Dec 08, 2006 10:15 am
Post subject: Re: Can Word sort a table by column rather than row? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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" <Campbell1555.RemoveThis@discussions.microsoft.com> wrote in message
news:8346A9B4-C644-4066-B0C2-2F7736D33F51@microsoft.com...
> 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
Back to top
Login to vote
Campbell1555

External


Since: Dec 08, 2006
Posts: 2



(Msg. 4) Posted: Fri Dec 08, 2006 12:06 pm
Post subject: Re: Can Word sort a table by column rather than row? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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 desire:
>
> 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" <Campbell1555.DeleteThis@discussions.microsoft.com> wrote in message
> > news:8346A9B4-C644-4066-B0C2-2F7736D33F51@microsoft.com...
> > > 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
>
>
Back to top
Login to vote
Greg Maxey

External


Since: Jan 08, 2006
Posts: 241



(Msg. 5) Posted: Fri Dec 08, 2006 5:06 pm
Post subject: Re: Can Word sort a table by column rather than row? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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" <Campbell1555 DeleteThis @discussions.microsoft.com> wrote in message
news:5A22019A-321E-43C4-A2B2-A28BE2723691@microsoft.com...
> 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 desire:
>>
>> 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" <Campbell1555 DeleteThis @discussions.microsoft.com> wrote in
>> > message
>> > news:8346A9B4-C644-4066-B0C2-2F7736D33F51@microsoft.com...
>> > > 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
>>
>>
Back to top
Login to vote
Greg Maxey

External


Since: Jan 08, 2006
Posts: 241



(Msg. 6) Posted: Fri Dec 08, 2006 6:13 pm
Post subject: Re: Can Word sort a table by column rather than row? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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 desire:
>>
>> 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" <Campbell1555.TakeThisOut@discussions.microsoft.com> wrote in
>>> message news:8346A9B4-C644-4066-B0C2-2F7736D33F51@microsoft.com...
>>>> 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
Back to top
Login to vote
Display posts from previous:   
       Home -> Office -> Tables All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows XP
 Windows Vista
 Windows Other
  Office
 Office Other
 Security
 WinRAR
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET