How to rotate a table?

R

Roger

I have a comlicated table for typesetting in our learned journal. For easy
layout, the table must be rotated for 90 CCW. I know a simple but very
time-cost way that manully copy data in raw into those in colunm one by one,
which I don't like. I think there should a better and efficient way like
that operates for a matrix. Thank you dearly. Roger
 
S

Suzanne S. Barnhill

If the table is the only thing on the page, then the usual solution is to
make the page a separate section and change the page orientation to
landscape (see http://word.mvps.org/FAQs/Formatting/LandscapeSection.htm. If
there's other text on the page, you can copy the table and paste it back as
a picture (using Edit | Paste Special). You'll need to change the wrapping
from In Line With Text to, say, Square in order to rotate it.
 
P

Pat Garard

G'Day Roger,

A "simple" rotation is not possible, BUT ...

Suppose you had:
A B C D
1 2 3 4
5 6 7 8

Copy and Paste the Table into Excel.

In Excel:
Select the table and Copy
Right-Click an empty cell below the selection - Choose Paste Special
In the dialog click "Transpose", then "OK"

You will now have:
A 1 5
B 2 6
C 3 7
D 4 8 i.e. a reflection in the major diagonal.

In this particular case you could also sort (descending) to give:
D 4 8
C 3 7
B 2 6
A 1 5 i.e. a complete reflection

If that helps you can now Copy and Paste back to Word.
 
H

Helmut Weber

Hi Pat,

a somewhat academic solution,
but I think, I'm close.

Sub Transpose()
Dim y As Long
Dim z As Long
Dim oTbl As Table
Dim sArr() As String
Dim sTmp As String
Dim x As Long
Dim lRow As Long
Dim lCol As Long
Set oTbl = ActiveDocument.Tables(1)
lRow = oTbl.Rows.Count
lCol = oTbl.Columns.Count
ReDim sArr(1 To oTbl.Range.Cells.Count)
For x = 1 To UBound(sArr)
sTmp = oTbl.Range.Cells(x).Range.Text
sTmp = Left(sTmp, (Len(sTmp) - 2))
sArr(x) = sTmp
Next
' --------------------------
For x = 1 To lRow - lCol
oTbl.Columns.Add
Next
For x = 1 To lCol - lRow
oTbl.Columns(1).Delete
Next
' --------------------------
For x = 1 To lRow - lCol
oTbl.Rows(1).Delete
Next
For x = 1 To lCol - lRow
oTbl.Rows.Add
Next
'--------------------------
x = 0
For y = 1 To oTbl.Columns.Count
For z = 1 To oTbl.Rows.Count
x = x + 1
oTbl.Cell(z, y).Range.Text = sArr(x)
Next
Next
End Sub

Have some fun.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

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