Convert vertical table to horizontal?

B

blewissmith

I have a table that lists vertically and I want to convert that table to list
item horizontally.
 
S

Suzanne S. Barnhill

Short of rotating the table itself, you can paste it into Excel using Edit |
Paste Special: Transpose, then copy/paste back to Word.
 
H

Helmut Weber

Hi,

if you know how to get a macro to work,
you might try this one,
which works for simple tables, as far as I see.

Simple means, no split or merged cells,
no table containing other tables,
no table containing objects like pictures etc.

Sub TransposeTable()
Dim C As Long ' column
Dim R As Long ' row

Dim x As Long ' just a counter
Dim y As Long ' just a counter
Dim z As Long ' just a counter

Dim STempo As String
Dim sArr() As String

With Selection
.Collapse
If Not .Information(wdWithInTable) Then
MsgBox "insertion point not in table"
Exit Sub
End If

With .Tables(1)
C = .Columns.Count
R = .Rows.Count
If R * C <> .Range.Cells.Count Then
MsgBox "split or merged cells"
Exit Sub
End If
ReDim sArr(1 To .Range.Cells.Count)
For x = 1 To UBound(sArr)
STempo = .Range.Cells(x).Range.Text
STempo = Left(STempo, (Len(STempo) - 2))
sArr(x) = STempo
Next
' --------------------------
With .Columns
For x = 1 To R - C
.Add
Next
For x = 1 To C - R
.Last.Delete
Next
End With
' --------------------------
With .Rows
For x = 1 To R - C
.Last.Delete
Next
For x = 1 To C - R
.Add
Next
End With
'--------------------------
' Transpose
'--------------------------
C = .Columns.Count
R = .Rows.Count
x = 0
For y = 1 To C
For z = 1 To R
x = x + 1
.Cell(z, y).Range.Text = sArr(x)
Next
Next
End With
End With

End Sub

HTH nevertheless

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