If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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] |
|
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Relationships set up | linronamy | New Users | 7 | February 20th, 2006 10:45 PM |
Criterion - How to Write Query for Multiple Tables | jcinn | Running & Setting Up Queries | 1 | February 8th, 2005 12:42 PM |
Appending data from one table to multiple relational tables | Stranger | Running & Setting Up Queries | 42 | August 18th, 2004 02:55 AM |
Mutliple Tables lookup? | Westley | Database Design | 4 | June 15th, 2004 01:07 AM |
How do I design a database based on the information that will be stored? - Copy of Tables and hirearchies.zip (0/1) | Jim | Database Design | 1 | June 1st, 2004 01:44 PM |