Converting Rows to columns

E

eraksoy

How do you convert Table 1 to Table2 in Word 2003 or 2007?

No A B
1 Arrow Black
2 Air Berry
Table 1

1 A Arrow
B Black
2 A Air
B Berry
Table 2
 
H

Herb Tyson [MVP]

Cheat. Copy it to Excel. Copy/paste special in Excel choosing the Transpose
option, then copy/paste it back into Word. :)
 
D

Doug Robbins - Word MVP

And, if you don't like cheating:

' Transposer Macro
' Macro creaeted 18/01/1999 by Doug Robbins
' to transpose rows and columns in a table
NumCols = ActiveDocument.Tables(1).Columns.Count
NumRows = ActiveDocument.Tables(1).Rows.Count
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=NumCols,
NumColumns:= _
NumRows
RowCounter = 0
While RowCounter < NumRows
ColCounter = 0
While ColCounter < NumCols
CellText = ActiveDocument.Tables(1).Cell(RowCounter + 1, ColCounter
+ 1).Range.Text
CellText = Left(CellText, Len(CellText) - 1)
ActiveDocument.Tables(2).Cell(ColCounter + 1, RowCounter +
1).Range.InsertBefore CellText
ColCounter = ColCounter + 1
Wend
RowCounter = RowCounter + 1
Wend


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
E

eraksoy

Dear Herb,
Thanks for your solution. Is there a way to convert Table 1 exactly into
Table 2?
I used Transpose function. It helped but it did not sort the table like A, B
and then A,B

"Herb Tyson [MVP]":
 
H

Herb Tyson [MVP]

I didn't study your 2nd table carefully before. I presumed because of the
subject line that you were transposing. Apparently not. Your example doesn't
swap rows and columns... it scrambles them, and the "to" table doesn't have
the same number of cells for each row:

A and B both appear twice in the 2nd table, and "No" doesn't appear at all.
The two tables' symmetry doesn't match.

A very specific macro might be able to do it, but I don't believe that
Doug's macro would do it, either.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top