Home » Questions » Computers [ Ask a new question ]

How can I get a cell in Excel to automatically adjust its height to fit the wrapped text contents? [duplicate]

How can I get a cell in Excel to automatically adjust its height to fit the wrapped text contents? [duplicate]

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?

Asked by: Guest | Views: 81
Total answers/comments: 4
Guest [Entry]

"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"
Guest [Entry]

"A VBA solution is to use the following:

Call Application.ActiveCell.AutoFit"
Guest [Entry]

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.
Guest [Entry]

"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"