I have a cell with wrapped text content in Excel and I want to format the cell so that its height will adjust to fit the content which can span over several lines. How can I achieve this behavior?
8 Answers
From http://support.microsoft.com/kb/149663
To adjust the height of the row to fit all the text in a cell, follow these steps:
Select the row.
In Microsoft Office Excel 2003 and in earlier versions of Excel, point to Row on the Format menu, and then click AutoFit.
In Microsoft Office Excel 2007, click the Home tab, click Format in the Cells group, and then click AutoFit Row Height.
Also Works when all the rows are selected
- 1,048
Try
Select the column -> right-click column -> Format Cells -> Alignment tab -> Wrap text
- 13,806
Note that autofit doesn't work on merged cells. You have to do it manually.
See this Microsoft answer:
You cannot use the AutoFit feature for rows or columns that contain merged cells in Excel
If it doesn't automatically do it, then place your cursor over the small line between row numbers (ex: between 1 and 2) and double click, this will resize the row (directly above the small line, in the example: 1) so that everything is visible (from a vertical aspect).
- 8,837
Do you know macro? Put the following code in
Application.ActiveCell.WrapText = True
inside your Worksheet_SelectionChange subroutine.
- 1,821
The only way I can get it to work as expected is to highlight the whole sheet with CTRL-A, unclick the "Wrap Text" button in the toolbar, then re-select it. No other settings change, but each row is now the "proper" height for its contents.
- 936
A VBA solution is to use the following:
Call Application.ActiveCell.AutoFit
- 12,847
- 1,322
I created the following VB code to resize the header row when a cell within a range (B2:B1500) because date values above 12/28/2014 would cause the header to show a warning that these dates, in a timesheet, would go into Week1 of 2015:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an Action when they are changed.
Set KeyCells = Range("B2:B1500")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
' Change the height of the header row when one of the defined cdlls is changed
Rows("1:1").EntireRow.AutoFit
End If
End Sub