Wrap Text in a Pivot Table

We used PivotTables to calculate, analyze and summarize data. This allows us to see trends, patterns, and comparisons in our data. Sometimes we may need to wrap text in a PivotTable. This tutorial shows you how to do it.

Example

We will use the following PivotTable in our illustrations:

How to Wrap Text in a PivotTable

We will show two methods that can be used to wrap text in a Pivot Table.

Methods 1: Use the Format Cells command

We use the following steps:

  1. Select cell A5 and right-click it.

Note: Select range A5:A8 in case you want to apply wrap text to that range at once.

  1. Click Format Cells on the shortcut menu.
  1. Select the Wrap text check box on the Alignment tab of the Format Cells dialog box. Then click the OK button:
Graphical user interface, application

Description automatically generated
  1. Reduce the width of column A and increase the height of row 5 to see the wrap text formatting in cell A5:
Graphical user interface, application, table, Excel

Description automatically generated

Note: To

Method 2: Use Excel VBA

  1. Press Alt + F11 in the active worksheet to open the Visual Basic Editor.
  2. Click Insert >> Module to insert a module.
  3. Type the code below in the module:
Sub wrapText()
    ActiveCell.wrapText = True
End Sub
  1. Save the procedure and save the workbook as a macro-enabled workbook.
  2. Press Alt + F11 to switch back to the PivotTable.
  3. Select cell A8 to make it the active cell.
  4. Press Alt + F11 to switch back to the code.
  5. Place the cursor anywhere in the procedure and press F5 to run the code.
  6. Press Alt + F11 to switch back to the PivotTable.
  7. Reduce the width of column A and increase the height of row 8 to see the wrap text formatting in cell A8:

Note: Repeat steps 6-10 to apply the formatting to any other cell in which you want to wrap text.

How to Keep the Format after Refresh

When you refresh the PivotTable the wrap text format is lost. To preserve the cell formatting after you refresh the PivotTable do the following:

  1. Select any cell in the PivotTable and right-click it.
  2. Click PivotTable Options on the shortcut menu.
  1. Select the Preserve cell formatting on update checkbox and click the OK button.

When you now refresh the PivotTable the wrap text formatting remains.

Conclusion

In this tutorial we have looked at two methods we can use to apply the wrap text formatting to cells in a PivotTable. We also looked at how to preserve the formatting after refreshing the Pivot Table.