Use a Word VBA Macro to Format Adjacent Table Columns
Question details
The user needs a Word macro that formats the table column containing the cursor and an adjacent column.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Apply a font name and size to two adjacent columns in a Word table.
- Observed behavior
- The macro should identify the cursor's column and format it along with the column on the chosen side.
Open the document in a desktop version of Word that supports VBA, and place the cursor inside a table cell. Use a regular table without merged cells for the macro below, and decide whether to format the column on the right or left.
Format the Current and Adjacent Columns with a VBA Macro
Use this macro to apply a font and size to every cell in the cursor's column and the column beside it.
The macro formats cell ranges directly, so it does not need to change the selection. It expects a table with uniform columns and no merged cells.
In desktop Word, open Developer > Visual Basic. If the Developer tab is hidden, enable it in Word's ribbon settings.
In the VBA editor, choose Insert > Module and paste this code: Sub FormatAdjacentColumns() Dim tbl As Table Dim cell As Cell Dim currentCol As Long Dim adjacentCol As Long Dim col As Long Const direction As Long = 1 ' Use -1 for the left column If Not Selection.Information(wdWithInTable) Then MsgBox "Place the cursor inside a table cell." Exit Sub End If Set tbl = Selection.Tables(1) currentCol = Selection.Cells(1).ColumnIndex adjacentCol = currentCol + direction If adjacentCol < 1 Or adjacentCol > tbl.Columns.Count Then MsgBox "There is no adjacent column on the chosen side." Exit Sub End If For col = 1 To tbl.Columns.Count If col = currentCol Or col = adjacentCol Then For Each cell In tbl.Columns(col).Cells cell.Range.Font.Name = "Arial" cell.Range.Font.Size = 11 Next cell End If Next col End Sub
In the module, leave direction as 1 for the right column or change it to -1 for the left column. Change "Arial" and 11 to the font name and size you want.
Return to the document, click inside a table cell, and choose View > Macros. Select FormatAdjacentColumns and click Run.
To keep the macro in the document, choose File > Save As and select Word Macro-Enabled Document (.docm).

Edit Word Tables with WPS Writer
WPS Office is a free, lightweight alternative for editing documents with a familiar interface. Open compatible Word files in WPS Writer to work with table formatting and move between office suites more easily. WPS does not fix Microsoft Word VBA issues, and macro support varies by edition.

Frequently Asked Questions
How do I format the column to the left instead of the right?
In the VBA module, change Const direction As Long = 1 to Const direction As Long = -1, then run FormatAdjacentColumns again.
What happens if the cursor is in the last column?
If the macro is set to use the right column, it displays a message and exits without formatting. Choose a different cell or set direction to -1.
Can I run this macro in Word for the web?
No. Open the document in a desktop version of Word that supports VBA, then use View > Macros to run it.
Why should I save the document as a DOCM file?
The DOCM format can retain VBA macros in the document. Choose File > Save As and select Word Macro-Enabled Document.




