Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
Cooz
 
Posts: n/a
Default The tables are turned! Well... not yet.

Hi everyone,

Is there a way to turn a Word table so that its columns become rows and its
rows become columns? If yes... how?

Thank you,
Cooz
  #2   Report Post  
Posted to microsoft.public.word.tables
macropod
 
Posts: n/a
Default The tables are turned! Well... not yet.

hi Cooz,

You can't turn rows into columns and vice-versa, as such. However, if all
you want to achieve is to have the text on side, select the relevant cells
and use Format|Text direction. Alternatively, put your table on a page laid
out in landscape if the rest of your document is portrait, or vice-versa.

Cheers

--
macropod
[MVP - Microsoft Word]


"Cooz" wrote in message
...
Hi everyone,

Is there a way to turn a Word table so that its columns become rows and

its
rows become columns? If yes... how?

Thank you,
Cooz



  #3   Report Post  
Posted to microsoft.public.word.tables
Suzanne S. Barnhill
 
Posts: n/a
Default The tables are turned! Well... not yet.

Although "macropod" has given you the options within Word, there is a way to
transpose the rows and columns, but it will work only if the table is fairly
simple (no merged cells, not too much fancy formatting). Copy the table in
Word, then open Excel and use Paste Special: Transpose. This will swap the
rows and columns, and you can then copy/paste the text back into Word.

--
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.

"Cooz" wrote in message
...
Hi everyone,

Is there a way to turn a Word table so that its columns become rows and

its
rows become columns? If yes... how?

Thank you,
Cooz


  #4   Report Post  
Posted to microsoft.public.word.tables
Helmut Weber
 
Posts: n/a
Default The tables are turned! Well... not yet.

Hi Cooz,

Is there a way to turn a Word table
so that its columns become rows and its
rows become columns? If yes... how?


yes and no,

simple only if the number of columns equals
the number of rows.
Otherwise you have to create a new table, based on the
data from the old table.

Rows x columns has always to be the same.

Fancy things like embedded tables,
split and merged cells, embedded objects etc.
would make it very difficult.

The principle for cells containing nothing but text
and regardless of formatting, is:

Sub Test0004()
Dim lCll As Long ' number of cells
Dim l As Long ' just a counter
lCll = ActiveDocument.Tables(1).Range.Cells.Count
' create an array representing all the cells
' from left to right for each row
ReDim aCell(1 To lCll) As String
For l = 1 To lCll
aCell(l) = ActiveDocument.Tables(1).Range.Cells(l).Range.Text
Next
' now you've got all text from all cells
' in a one dimensional array
' and can arrange the data as you please
End Sub

Theory only.
Get Excel to help you, as Suzanne recommended.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"






  #5   Report Post  
Posted to microsoft.public.word.tables
Cooz
 
Posts: n/a
Default The tables are turned! Well... not yet.

Thank you, macropod, Suzanne and Helmut for your response.

Cooz



"Cooz" wrote:

Hi everyone,

Is there a way to turn a Word table so that its columns become rows and its
rows become columns? If yes... how?

Thank you,
Cooz



  #6   Report Post  
Posted to microsoft.public.word.tables
Bob S
 
Posts: n/a
Default The tables are turned! Well... not yet.

I was looking at this and found a way to do it entirely in Word with
no macros. It is a bit tedious if the table has a lot of columns
though...

Make some spare space below your table with empty paragraphs. Select
and copy the first column of the table and paste it into the spare
space, giving you a one-column table. Select and copy the second
column of the original table and paste it immediately below the new
table, giving you a longer one column table. Keep doing this until you
have done every column in the original table. Now select the new
one-column table, convert it to text, and convert it back to a table
with the proper number of columns (i.e. the original number of rows).

Bob S

On Fri, 2 Jun 2006 07:49:01 -0700, Cooz wrote:

Hi everyone,

Is there a way to turn a Word table so that its columns become rows and its
rows become columns? If yes... how?

Thank you,
Cooz


  #7   Report Post  
Posted to microsoft.public.word.tables
Cooz
 
Posts: n/a
Default The tables are turned! Well... not yet.

Hi Bob,

That's one fine solution. Thank you!

Cooz



"Bob S" wrote:

I was looking at this and found a way to do it entirely in Word with
no macros. It is a bit tedious if the table has a lot of columns
though...

Make some spare space below your table with empty paragraphs. Select
and copy the first column of the table and paste it into the spare
space, giving you a one-column table. Select and copy the second
column of the original table and paste it immediately below the new
table, giving you a longer one column table. Keep doing this until you
have done every column in the original table. Now select the new
one-column table, convert it to text, and convert it back to a table
with the proper number of columns (i.e. the original number of rows).

Bob S

On Fri, 2 Jun 2006 07:49:01 -0700, Cooz wrote:

Hi everyone,

Is there a way to turn a Word table so that its columns become rows and its
rows become columns? If yes... how?

Thank you,
Cooz



  #8   Report Post  
Posted to microsoft.public.word.tables
Tesla Tesla is offline
external usenet poster
 
Posts: 5
Default The tables are turned! Well... not yet.

Yes, there is. It involves a small macro that the vendor does not ship with
the product. I am sorry that this forum danced around the issue and gave you
no good advice.

This is a complete solution, which handles multiple tables selected, of any
size, even with embedded OLE objects in the cells, and keeps the original
formatting of the table. I worked Equations objects successfully in them.

Do not panic with the seemingly chaotic dance of tables and selections in
the document during processing, it all works nicely.

Here it is:
Option Explicit
' Author: Sidney, like I need to give a last name!
Sub TransposeTablesSelected()
Dim t As Table
For Each t In Selection.Tables
TransposeTable t
Next
End Sub
Sub TransposeTable(t As Table)
Dim original_rows As Integer
original_rows = t.Rows.Count

Dim original_cols As Integer
original_cols = t.Columns.Count

Dim diagonal_count As Integer
diagonal_count = IIf(original_rows original_cols, original_rows,
original_cols)

' increase size
Do While t.Rows.Count diagonal_count
t.Rows.Add
Loop
Do While t.Columns.Count diagonal_count
t.Columns.Add
Loop

' Auxiliary holder of table cell
Selection.MoveUp Unit:=wdLine, Count:=1
Dim auxTable As Table
Set auxTable = ActiveDocument.Tables.Add(Range:=Selection.Range,
NumRows:=2, NumColumns:= _
2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitContent)

Dim j As Integer
Dim k As Integer
For k = 1 To diagonal_count
For j = k + 1 To diagonal_count
Call TableCellSwap(t, k, j, auxTable, j, k)
Next
Next

auxTable.Delete

' decrease size
Do While t.Rows.Count original_cols
t.Rows(t.Rows.Count).Delete
Loop
Do While t.Columns.Count original_rows
t.Columns(t.Columns.Count).Delete
Loop
End Sub
Sub TableCellMove(sourceTable As Table, sourceRow As Integer, sourceCol As
Integer, destTable As Table, destRow As Integer, destCol As Integer)
sourceTable.Cell(sourceRow, sourceCol).Select
Selection.Cut

destTable.Cell(destRow, destCol).Select
Selection.Paste
End Sub
Sub TableCellSwap(sourceTable As Table, sourceRow As Integer, sourceCol As
Integer, auxTable As Table, destRow As Integer, destCol As Integer)
Call TableCellMove(sourceTable, destRow, destCol, auxTable, 1, 1)
Call TableCellMove(sourceTable, sourceRow, sourceCol, sourceTable,
destRow, destCol)
Call TableCellMove(auxTable, 1, 1, sourceTable, sourceRow, sourceCol)
End Sub


"Cooz" wrote:

Hi everyone,

Is there a way to turn a Word table so that its columns become rows and its
rows become columns? If yes... how?

Thank you,
Cooz

  #9   Report Post  
Posted to microsoft.public.word.tables
Pat Garard Pat Garard is offline
external usenet poster
 
Posts: 301
Default The tables are turned! Well... not yet.

Hi Sweetheart,

Yes, there is. It involves a small macro that the vendor does not ship with ..

Thank you SO MUCH for a lesson in matrix transposition. Of course the
Vendor actually shipped the solution in Excel ...

99.9% of Word Users do not need matrices ...
99.9% of Excel Users MIGHT ....

I feel so ... enriched ...
--
Regards,
Pat Garard
Melbourne, Australia
_______________________

"Tesla" wrote in message
...
Yes, there is. It involves a small macro that the vendor does not ship with
the product. I am sorry that this forum danced around the issue and gave you
no good advice.

This is a complete solution, which handles multiple tables selected, of any
size, even with embedded OLE objects in the cells, and keeps the original
formatting of the table. I worked Equations objects successfully in them.

Do not panic with the seemingly chaotic dance of tables and selections in
the document during processing, it all works nicely.

Here it is:
Option Explicit
' Author: Sidney, like I need to give a last name!
Sub TransposeTablesSelected()
Dim t As Table
For Each t In Selection.Tables
TransposeTable t
Next
End Sub
Sub TransposeTable(t As Table)
Dim original_rows As Integer
original_rows = t.Rows.Count

Dim original_cols As Integer
original_cols = t.Columns.Count

Dim diagonal_count As Integer
diagonal_count = IIf(original_rows original_cols, original_rows,
original_cols)

' increase size
Do While t.Rows.Count diagonal_count
t.Rows.Add
Loop
Do While t.Columns.Count diagonal_count
t.Columns.Add
Loop

' Auxiliary holder of table cell
Selection.MoveUp Unit:=wdLine, Count:=1
Dim auxTable As Table
Set auxTable = ActiveDocument.Tables.Add(Range:=Selection.Range,
NumRows:=2, NumColumns:= _
2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitContent)

Dim j As Integer
Dim k As Integer
For k = 1 To diagonal_count
For j = k + 1 To diagonal_count
Call TableCellSwap(t, k, j, auxTable, j, k)
Next
Next

auxTable.Delete

' decrease size
Do While t.Rows.Count original_cols
t.Rows(t.Rows.Count).Delete
Loop
Do While t.Columns.Count original_rows
t.Columns(t.Columns.Count).Delete
Loop
End Sub
Sub TableCellMove(sourceTable As Table, sourceRow As Integer, sourceCol As
Integer, destTable As Table, destRow As Integer, destCol As Integer)
sourceTable.Cell(sourceRow, sourceCol).Select
Selection.Cut

destTable.Cell(destRow, destCol).Select
Selection.Paste
End Sub
Sub TableCellSwap(sourceTable As Table, sourceRow As Integer, sourceCol As
Integer, auxTable As Table, destRow As Integer, destCol As Integer)
Call TableCellMove(sourceTable, destRow, destCol, auxTable, 1, 1)
Call TableCellMove(sourceTable, sourceRow, sourceCol, sourceTable,
destRow, destCol)
Call TableCellMove(auxTable, 1, 1, sourceTable, sourceRow, sourceCol)
End Sub


"Cooz" wrote:

Hi everyone,

Is there a way to turn a Word table so that its columns become rows and its
rows become columns? If yes... how?

Thank you,
Cooz



  #10   Report Post  
Posted to microsoft.public.word.tables
macropod macropod is offline
external usenet poster
 
Posts: 1,002
Default The tables are turned! Well... not yet.

I am sorry that this forum danced around the issue and gave you
no good advice.


Really? The other solutions offered all do the job in various ways, at least
one of which met the OP's needs.

Your code needs more work. I tried it with a 5-column, 4-row table and
nothing was transposed. Plus, if the table is at the very top of the
document, the code crashes.

Cheers

--
macropod
[MVP - Microsoft Word]




  #11   Report Post  
Posted to microsoft.public.word.tables
Tesla Tesla is offline
external usenet poster
 
Posts: 5
Default The tables are turned! Well... not yet.

Thanks for reporting the problem with the macro.
Please see second posting, which addresses the problem by not using an
auxiliary table.

"macropod" wrote:

I am sorry that this forum danced around the issue and gave you
no good advice.


Really? The other solutions offered all do the job in various ways, at least
one of which met the OP's needs.

Your code needs more work. I tried it with a 5-column, 4-row table and
nothing was transposed. Plus, if the table is at the very top of the
document, the code crashes.

Cheers

--
macropod
[MVP - Microsoft Word]



  #12   Report Post  
Posted to microsoft.public.word.tables
Tesla Tesla is offline
external usenet poster
 
Posts: 5
Default The tables are turned! Well... not yet.

Everyone thank macropod for alpha testing the macro, here is version 2, much
improved:

Option Explicit
Sub TransposeTableSelected()
Dim c As New Collection
Dim o
For Each o In Selection.Tables
c.Add o
Next
Dim t As Table
For Each t In c
TransposeTable t
Next
End Sub
Sub TransposeTable(t As Table)
If t Is Nothing Then
Exit Sub
End If
Dim original_rows As Integer
original_rows = t.Rows.Count

Dim original_cols As Integer
original_cols = t.Columns.Count

Dim diagonal_count As Integer
diagonal_count = IIf(original_rows original_cols, original_rows,
original_cols)

' increase size
Do While t.Rows.Count diagonal_count
t.Rows.Add
Loop
Do While t.Columns.Count diagonal_count
t.Columns.Add
Loop
' add a row to hold values as they are shuffled.
t.Rows.Add

Dim j As Integer
Dim k As Integer
For k = 1 To diagonal_count
For j = k + 1 To diagonal_count
Call TableCellSwap(t, k, j, j, k)
Next
Next

' decrease size
Do While t.Rows.Count original_cols
t.Rows(t.Rows.Count).Delete
Loop
Do While t.Columns.Count original_rows
t.Columns(t.Columns.Count).Delete
Loop
End Sub
Sub TableCellMove(sourceTable As Table, sourceRow As Integer, sourceCol As
Integer, destTable As Table, destRow As Integer, destCol As Integer)
sourceTable.Cell(sourceRow, sourceCol).Select
Selection.Cut

destTable.Cell(destRow, destCol).Select
Selection.Paste
End Sub
Sub TableCellSwap(sourceTable As Table, sourceRow As Integer, sourceCol As
Integer, destRow As Integer, destCol As Integer)
Call TableCellMove(sourceTable, destRow, destCol, sourceTable,
sourceTable.Rows.Count, 1)
Call TableCellMove(sourceTable, sourceRow, sourceCol, sourceTable,
destRow, destCol)
Call TableCellMove(sourceTable, sourceTable.Rows.Count, 1, sourceTable,
sourceRow, sourceCol)
End Sub


"Tesla" wrote:

Yes, there is. It involves a small macro that the vendor does not ship with
the product. I am sorry that this forum danced around the issue and gave you
no good advice.

This is a complete solution, which handles multiple tables selected, of any
size, even with embedded OLE objects in the cells, and keeps the original
formatting of the table. I worked Equations objects successfully in them.

Do not panic with the seemingly chaotic dance of tables and selections in
the document during processing, it all works nicely.

Here it is:


see version 2 above.
  #13   Report Post  
Posted to microsoft.public.word.tables
Tesla Tesla is offline
external usenet poster
 
Posts: 5
Default The tables are turned! Well... not yet.

Your tone is not welcome. And you have not contributed to a solution.

This is a discussion about transposing tables in Word;
not matrices, not Excel documents.

99.9% of statistics are made up by the people that quote them.

"Pat Garard" wrote:

Hi Sweetheart,

Yes, there is. It involves a small macro that the vendor does not ship with ..

Thank you SO MUCH for a lesson in matrix transposition. Of course the
Vendor actually shipped the solution in Excel ...

99.9% of Word Users do not need matrices ...
99.9% of Excel Users MIGHT ....

I feel so ... enriched ...
--
Regards,
Pat Garard
Melbourne, Australia


  #14   Report Post  
Posted to microsoft.public.word.tables
macropod macropod is offline
external usenet poster
 
Posts: 1,002
Default The tables are turned! Well... not yet.

Still needs more work - bombs on tables with merged cells.

Cheers

--
macropod
[MVP - Microsoft Word]


"Tesla" wrote in message
...
Everyone thank macropod for alpha testing the macro, here is version 2,

much
improved:

Option Explicit
Sub TransposeTableSelected()
Dim c As New Collection
Dim o
For Each o In Selection.Tables
c.Add o
Next
Dim t As Table
For Each t In c
TransposeTable t
Next
End Sub
Sub TransposeTable(t As Table)
If t Is Nothing Then
Exit Sub
End If
Dim original_rows As Integer
original_rows = t.Rows.Count

Dim original_cols As Integer
original_cols = t.Columns.Count

Dim diagonal_count As Integer
diagonal_count = IIf(original_rows original_cols, original_rows,
original_cols)

' increase size
Do While t.Rows.Count diagonal_count
t.Rows.Add
Loop
Do While t.Columns.Count diagonal_count
t.Columns.Add
Loop
' add a row to hold values as they are shuffled.
t.Rows.Add

Dim j As Integer
Dim k As Integer
For k = 1 To diagonal_count
For j = k + 1 To diagonal_count
Call TableCellSwap(t, k, j, j, k)
Next
Next

' decrease size
Do While t.Rows.Count original_cols
t.Rows(t.Rows.Count).Delete
Loop
Do While t.Columns.Count original_rows
t.Columns(t.Columns.Count).Delete
Loop
End Sub
Sub TableCellMove(sourceTable As Table, sourceRow As Integer, sourceCol As
Integer, destTable As Table, destRow As Integer, destCol As Integer)
sourceTable.Cell(sourceRow, sourceCol).Select
Selection.Cut

destTable.Cell(destRow, destCol).Select
Selection.Paste
End Sub
Sub TableCellSwap(sourceTable As Table, sourceRow As Integer, sourceCol As
Integer, destRow As Integer, destCol As Integer)
Call TableCellMove(sourceTable, destRow, destCol, sourceTable,
sourceTable.Rows.Count, 1)
Call TableCellMove(sourceTable, sourceRow, sourceCol, sourceTable,
destRow, destCol)
Call TableCellMove(sourceTable, sourceTable.Rows.Count, 1,

sourceTable,
sourceRow, sourceCol)
End Sub


"Tesla" wrote:

Yes, there is. It involves a small macro that the vendor does not ship

with
the product. I am sorry that this forum danced around the issue and gave

you
no good advice.

This is a complete solution, which handles multiple tables selected, of

any
size, even with embedded OLE objects in the cells, and keeps the

original
formatting of the table. I worked Equations objects successfully in

them.

Do not panic with the seemingly chaotic dance of tables and selections

in
the document during processing, it all works nicely.

Here it is:


see version 2 above.



  #15   Report Post  
Posted to microsoft.public.word.tables
Tesla Tesla is offline
external usenet poster
 
Posts: 5
Default The tables are turned! Well... not yet.

One more restriction to that approach: unfortunately that does not handle all
the things that can be in a cell, such as Objects (see MS Equation) or
captions, when one goes from Word to Excel.

The quest continues.

"Suzanne S. Barnhill" wrote:

Although "macropod" has given you the options within Word, there is a way to
transpose the rows and columns, but it will work only if the table is fairly
simple (no merged cells, not too much fancy formatting). Copy the table in
Word, then open Excel and use Paste Special: Transpose. This will swap the
rows and columns, and you can then copy/paste the text back into Word.

--
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.

"Cooz" wrote in message
...
Hi everyone,

Is there a way to turn a Word table so that its columns become rows and

its
rows become columns? If yes... how?

Thank you,
Cooz



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
Changing format of multiple pre-created tables Wendy Microsoft Word Help 2 September 14th 05 08:55 AM
When joining tables, table sections shift left or right. JEB01 Tables 1 January 17th 05 07:57 PM
Merging tables in Word 2003 JoanN Microsoft Word Help 3 December 21st 04 06:35 PM
Is there a way to "join" tables in Word 2003? Julian Turner Tables 3 October 28th 04 06:51 PM


All times are GMT +1. The time now is 08:07 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"