Dim NewRwHt As Single Dim cWdth As Single, MrgeWdth As Single Dim c As Range, cc As Range Dim ma As Range With Target If .MergeCells And .WrapText Then Set c = Target.Cells(1, 1) cWdth = c.ColumnWidth Set ma = c.MergeArea For Each cc In ma.Cells MrgeWdth = MrgeWdth + cc.ColumnWidth Next Application.ScreenUpdating = False ma.MergeCells = False c.ColumnWidth = MrgeWdth c.EntireRow.AutoFit NewRwHt = c.RowHeight c.ColumnWidth = cWdth ma.MergeCells = True ma.RowHeight = NewRwHt cWdth = 0: MrgeWdth = 0 Application.ScreenUpdating = True End If End With End Sub
Open VBA window by pressing the key combination Alt + F11 , On the Sheet name contains the cell you want to automatically wrap the line you right-click select Insert -> Module .
How to automatically wrap lines in Excel (Wrap Text in Excel) Picture 6
Copy the above code into the Module window.
How to automatically wrap lines in Excel (Wrap Text in Excel) Picture 7
Return to Work Sheet, double-click the cell you want to auto-break, and then press the Enter button to automatically wrap the line.
The result is as shown below:
How to automatically wrap lines in Excel (Wrap Text in Excel) Picture 8