Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Adjusting Row Height when Wrapping Text.

Adjusting Row Height when Wrapping Text

Written by Allen Wyatt (last updated July 24, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


6

Matt asked if there is a way to format a merged cell so that when the content of the cell exceeds the width, the row height is automatically adjusted to display the additional lines necessary.

Unfortunately, AutoFit (which Excel uses for row height) doesn't work with merged cells. There are ways around this problem, but none of them are easy or automatic. For this reason, you might consider re-designing your worksheet so that it doesn't use merged cells. If you must use them, then you might try this little trick, assuming the merged cells are in A2:M2:

  1. Select a cell that is distinct and apart from your data table. For instance, if your data table is in A2:M45, select a cell such as P55.
  2. In the cell, enter the formula =A2. Cell P55 should now contain the same text that was in the merged cells (A2:M2).
  3. Make sure that the formatting of cell P55 is the same as the formatting of cells A2:M2. The only formatting that should be different is that cell P55 should not be merged with any other cell in any manner. Make sure, as well, that the cell's Wrap setting is turned on.
  4. Calculate the combined width of all the cells that make up the merged cell. For instance, if columns A through M have individual widths of 9, then the combined width would be 117 (9 x 13). Subtract 2 from this sum (117 - 2 = 115).
  5. Set the width of column P to the calculated width you determined in step 4. Your text should now be wrapped to multiple lines, and the row height automatically adjusts.
  6. Check the row height of row 55 (display the Home tab of the ribbon and click Format | Row Height in the Cells group).
  7. Manually set the height of row 2 to the same row height you determined in step 6.
  8. Delete column P and row 55.

You might wonder why, in step 4, you subtracted 2 from your original calculated width. This is just a "fudge factor" used to force a slightly narrower column width, and therefore slightly different word wrapping. This comes in handy when you are later viewing your worksheet using a different zoom factor or when you are using a different printer driver.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10228) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Adjusting Row Height when Wrapping Text.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Specifying Superscript Text

Applying different formatting to the text within a cell can seem a bit confusing. This is certainly the case when it ...

Discover More

Listing Combinations

You can easily use the COMBIN worksheet function to determine the number of combinations that can be made from a given ...

Discover More

Best Way to Create a Document Template

Templates are the basis of creating consistent documents that permit fast and easy formatting. What is the best way to ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Formatting Subtotal Rows

Excel automatically formats subtotals for you. But what if you want to change the default to something more suitable for ...

Discover More

Hiding and Unhiding Rows

When building a worksheet, you may need to hide some of the rows or unhide other, previously hidden, rows. It's easy to ...

Discover More

Adjusting Row Height for Your Text

Want Excel to automatically adjust the height of a worksheet row when it wraps text within the cell? It's easy to do, ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two more than 7?

2020-07-26 04:16:59

Peter Atherton

As a matter of general interest Ed (in 2015) asked about calulating the combind width of cells. The following does this.

Function getWidth(ref As Range) As Integer
Dim c As Range, w As Long
For Each c In ref
w = w + Round(c.Width * 0.186, 0)
Next
getWidth = w
End Function

Entered as =GETWIDTH(C1:F1)


2020-07-25 10:34:17

Philip Andrew

Unfortunately, even for un-merged/single cells, AutoFit Row Height doesn’t seem to work. Something to do with cells that have undergone manual height adjustment at some point permanently inactivates AutoFit Row Height? Any help much appreciated.


2020-07-24 09:44:41

Kiwerry

@Allen: Thanks again for a useful site & newsletter - I enjoy the personal touch in the newsletters as well as the helpful tips.

As far as this tip is concerned, two comments:
1) a quick attempt showed that it may be possible to dispense with your steps 6 and 7 if, instead of putting the dummy cell (P55 in your example) way below and to the right of the data, put it on the same row as your merged cell but well over to the right of the data (P2 in your example). An auto-resize on the worksheet will set the correct height for this row. Reminder on auto-resize: Type Control-A to select the entire worksheet then double click with a double arrow on any column or row border. For some unknown reason, I had to use a fudge factor of +2 instead of Allen's -2 on the text I used if I wanted the appearance of A2:C2 to be the same as that of P2; otherwise the line breaks occurred in slightly different places.
2) If your merged cells are centre aligned, then consider using "Center across Selection" as the horizontal alignment instead of using "Merge and Center" on the cells.

@Kevin: I have also fallen into the trap of writing an answer on a post, then finding that the post was pretty old;-}} By the way, imo methods involving the number of characters (i.e. using the length function) only work well if you are using a non-proportional font like Courier.

@Ed: you could use a formula like =CELL("width",A2)+CELL("width",B2)+CELL("width",C2) to show you the combined widths of columns A to C, but a) the formula will only work where the cells in the row referred to are not merged (if they're merged you get a SPILL error, but the workaround is easy - just refer to a row which is outside your data), and b) if the problem only occurs once in a worksheet it may easier to just count and add.


2020-07-24 03:44:44

Kevin

Hi John - Read and created before looking at your date of enquiry so in the unlikely event that you or anyone else is still looking for this.
My example was based around adjusting the row height for text that was only either 1 or 2 rows of text.
You might be able to work your own solution based on these crude methods.
This example relates to - On the worksheet a formula to indicate the length of text (=LEN(V62) at Z62 Where the first cell of the merged cells was V62
Within your Macro parts
Dim r As Variant
' Make the Row Heights suit the text of the Prizes
r = "62" ' Row height to change
If Rows(r).EntireRow.Hidden = True Then
Else
If Sheets("Yours").Range("Z62").Value > 42 Then
Rows(r).RowHeight = 30
Else
Rows(r).RowHeight = 15
End If
End If

Good luck


2016-01-21 22:14:25

John Smith

Any way to programmatically calculate height of wrapped text? I need to do this because I programmatically insert pictures to rows and adjust row height to fit the picture. This way, pictures are displayed alright. But some rows are not tall enough to display wrapped text. I need a way to calculate and adjust the height of wrapped text so all text is displayed.


2015-07-28 10:26:35

Ed

What is the easiest way to (step 4) "calculate the combined width of all the cells that make up the merged cell"?
Given that I do not want to change the width of those columns. Is there anything faster than checking them each, one at a time?


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.