Hi

Is it possible to distribute some of the columns in a table evenly or do I have to select all? The message I get is 'you must select multiple columns' When I do this the table toolbar greys out the option!

Dani AI

Generated

Good points from and — add this practical explanation and a small workaround.

Word’s Distribute Columns command is deliberately picky: it only runs when the columns you selected are part of the table’s intact column grid. Two common causes of the gray/“you must select multiple columns” behavior are (a) the selection isn’t really a single contiguous grid slice (Ctrl-clicking can produce odd selections) and (b) one or more rows contain cells that span those column boundaries (headers, footers or merged cells). When a cell spans multiple grid columns Word can’t compute a single per-column width for that row, so the GUI disables the command.

Quick troubleshooting checklist

  • Verify the selection is contiguous (use the column drag/selector rather than Ctrl-click).
  • Scan header/footer rows for cells that run across multiple columns; split those cells (or temporarily split the table) so the table grid is consistent, run the distribute operation, then remerge if needed.
  • Always save a copy before splitting/merging header rows — splitting can change cell formatting and line breaks.

If you want a one-click workaround that ignores the GUI limitation, this VBA macro equalizes the widths of the columns that contain any selected cells (it reads the selected cells’ column indexes and redistributes the total width evenly across them). Paste into Word’s VBA editor (Tools → Macro → Visual Basic Editor → Insert → Module), select cells in the columns you want adjusted, then run the macro.

Sub DistributeSelectedColumnsEvenly()
    Dim t As Table
    Dim c As Cell
    Dim colIndices As Collection
    Dim i As Long, tmp As Long
    Dim cols() As Long
    Dim totalWidth As Single, newWidth As Single

    If Selection.Tables.Count = 0 Then
        MsgBox "Place the cursor inside a table or select at least one table cell."
        Exit Sub
    End If

    Set t = Selection.Tables(1)
    Set colIndices = New Collection
    On Error Resume Next
    For Each c In Selection.Cells
        colIndices.Add c.ColumnIndex, CStr(c.ColumnIndex)
    Next c
    On Error GoTo 0

    If colIndices.Count = 0 Then
        MsgBox "Select at least one cell in each column you want to distribute."
        Exit Sub
    End If

    ReDim cols(1 To colIndices.Count)
    For i = 1 To colIndices.Count: cols(i) = CLng(colIndices(i)): Next i

    ' simple bubble sort
    For i = LBound(cols) To UBound(cols) - 1
        For j = i + 1 To UBound(cols)
            If cols(i) > cols(j) Then
                tmp = cols(i): cols(i) = cols(j): cols(j) = tmp
            End If
        Next j
    Next i

    totalWidth = 0
    For i = LBound(cols) To UBound(cols)
        totalWidth = totalWidth + t.Columns(cols(i)).Width
    Next i

    newWidth = totalWidth / (UBound(cols) - LBound(cols) + 1)
    For i = LBound(cols) To UBound(cols)
        t.Columns(cols(i)).Width = newWidth
    Next i
End Sub

This uses the table Cell.ColumnIndex and Columns.Width functionality in Word’s object model. (learn.microsoft.com)

Caveat: the macro changes column widths directly — keep a backup and reapply any header/footer merges afterward if you split them to make the GUI work.

Recommended Answers

All 5 Replies

This is easy:

1. Using the downpointing black arrow mouse pointer (appears at the top of a column), select the columns you want distributed evenly by dragging across their tops.

2. Use the Table menu / autofit / Distribute columns evenly.

commented: Nice and clear +1

Thanks Midimagic,

I had been selecting the columns using the black arrow and holding down the CTRL key. When the columns are selected using that method the Autofit options are unavailable. Must be some sort of bug.

Geoff

Ctrl allows nonconsecutive columns to be selected. Autofit requires them to be consecutive.

Ctrl allows nonconsecutive columns to be selected. Autofit requires them to be consecutive.

So Word rejects columns selected with the Ctrl key even though they may be consecutive, which they were when I tried?

Member Avatar for Member #274676

Hi

Is it possible to distribute some of the columns in a table evenly or do I have to select all? The message I get is 'you must select multiple columns' When I do this the table toolbar greys out the option!

Hi there,

I was just looking for how to do this myself. I had acutally done it before so I was confused why I couldn't find it again. If you haven't already figured it out...it turns out that if you have any merged cells in your table above or below the columns you want to distribute, you cannot distribute a set of columns evenly. (Even if you just select those columns). For instance, I had a header row and a bottom row with a "footnote" in my table. I had to split each of those rows into the same number of columns as the rest of the table, select those "extra" columns with the columns I wanted to distribute evenly. Then, when I right clicked - the option to distribute columns appeared. (I don't know why it doesn't show otherwise in a grayed out format so you can easily see that is an available function when done "correctly). Then I had to re-merge my header and "footer" rows. Annoying! I guess another option would be to split those rows off the table and then reattach them. (This was using Vista)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.