Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Changing format of multiple pre-created tables | Microsoft Word Help | |||
When joining tables, table sections shift left or right. | Tables | |||
Merging tables in Word 2003 | Microsoft Word Help | |||
Is there a way to "join" tables in Word 2003? | Tables |