Skip to content

Transpose a Table in Word: VBA Macro and Excel Alternative

  • by
Transpose table in Ms Word in 1 Click

Word has no built-in Transpose Table command. This guide explains the VBA approach and a safer Excel-based alternative for swapping rows and columns.

Before you start: what a Word table transpose changes

  1. Save a backup copy of the document. Transposing changes an R-by-C table into a C-by-R table.
  2. Use a simple rectangular table without merged or nested cells; this text-only macro does not preserve individual cell formatting, images, or fields.
  3. In desktop Word, open the VBA editor with Alt + F11 (Windows), insert a standard module, paste the code below, and run TransposeWordTableSafely while the cursor is inside the table. Mac shortcuts and macro access differ.
  4. Compare the newly inserted table with the original before manually removing anything. The macro deliberately keeps the original table.
Option Explicit
Public Sub TransposeWordTableSafely()
    Dim source As Table, result As Table
    Dim r As Long, col As Long, rowsN As Long, colsN As Long
    Dim textValue As String, destination As Range
    If Not Selection.Information(wdWithInTable) Then
        MsgBox "Place the cursor inside a table first.", vbExclamation
        Exit Sub
    End If
    Set source = Selection.Tables(1)
    On Error GoTo UnsupportedTable
    rowsN = source.Rows.Count
    colsN = source.Columns.Count
    'Read all cells before creating output; this example is for simple tables.
    Dim values() As String
    ReDim values(1 To rowsN, 1 To colsN)
    For r = 1 To rowsN
        For col = 1 To colsN
            textValue = source.Cell(r, col).Range.Text
            values(r, col) = Left$(textValue, Len(textValue) - 2)
        Next col
    Next r
    'Insert after the source table; leave the original intact for checking.
    Set destination = source.Range.Duplicate
    destination.Collapse wdCollapseEnd
    destination.InsertParagraphAfter
    destination.Collapse wdCollapseEnd
    Set result = ActiveDocument.Tables.Add(destination, colsN, rowsN)
    For r = 1 To rowsN
        For col = 1 To colsN
            result.Cell(col, r).Range.Text = values(r, col)
        Next col
    Next r
    MsgBox "Transposed copy created. Compare it with the original.", vbInformation
    Exit Sub
UnsupportedTable:
    MsgBox "Could not transpose this table. Use a simple rectangular table without merged or nested cells; the original was not deleted.", vbExclamation
End Sub

Video demonstration (may show an earlier macro)

No-code alternative: transpose through Excel

For example, a Word table with 2 rows and 3 columns becomes a table with 3 rows and 2 columns. Copy the table into an empty Excel sheet, select the pasted cells, copy them, choose a blank destination and use Paste Special > Transpose (or the Transpose paste option), then paste the result back into Word. Check whether numbers, line breaks and formatting survived the transfer. This avoids running VBA and is often preferable for complex content.

Troubleshooting, limitations and accuracy notes

Important: the VBA macro above is designed for simple text-only tables. It removes Word’s two trailing end-of-cell characters before copying cell text. It does not copy cell shading, borders, hyperlinks, images, tracked changes or other rich formatting. Tables with merged or nested cells can trigger an error. The original table is not intentionally deleted, but an interrupted macro may leave a partial new table: use Undo or your backup to recover. Run macros only in trusted documents and inspect the result cell by cell.

Frequently asked questions

Can I transpose in Word for the web? Word for the web cannot run VBA macros; use the Excel method instead. Will formulas and formatting transpose? No. This example copies plain cell text only. Why not delete the source table automatically? Keeping the original makes it possible to verify every transposed cell and recover from mistakes.

Related guides: AutoFit a Table in Word: Fit Contents, Window or Fixed Width · Microsoft Word Table Keyboard Shortcuts for Windows and Mac · Flatten an Excel Range into One Column with TOCOL or VBA

Leave a Reply

Your email address will not be published. Required fields are marked *