VBA & Macro Problems

Use a Word VBA Macro to Format Adjacent Table Columns

Anum MushtaqAnum Mushtaq Nov 20, 2026 869 views

Question details

The user needs a Word macro that formats the table column containing the cursor and an adjacent column.

Format Adjacent Table Columns with a Word VBA Macro
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In desktop Word, open Developer > Visual Basic. If the Developer tab is hidden, enable it in Word's ribbon settings.

2
Add the macro

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

3
Choose the side and formatting

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.

4
Run the macro

Return to the document, click inside a table cell, and choose View > Macros. Select FormatAdjacentColumns and click Run.

5
Save the macro

To keep the macro in the document, choose File > Save As and select Word Macro-Enabled Document (.docm).

Format the Current and Adjacent Columns with a VBA Macro
Merged cells and table edges: The macro stops if there is no column on the chosen side. Tables with merged cells may not support column access as expected; use an unmerged table or adapt the code for that table.
Free Microsoft Office alternative

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.

Format table text and columns in WPS WriterOpen and edit Microsoft Word DOC and DOCX filesUse a familiar interface for everyday document editingWork with a free, lightweight office suite
microsoft office alternative - wps office

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.