**Please Note: **
This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 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.

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:

- 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.
- In the cell, enter the formula =A2. Cell P55 should now contain the same text that was in the merged cells (A2:M2).
- 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.
- 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).
- 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.
- Check the row height of row 55 (display the Home tab of the ribbon and click Format | Row Height in the Cells group).
- Manually set the height of row 2 to the same row height you determined in step 6.
- 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 Office 365. You can find a version of this tip for the older menu interface of Excel here: **Adjusting Row Height when Wrapping Text**.

**Solve Real Business Problems** Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out *Microsoft Excel 2013 Data Analysis and Business Modeling* today!

Need to check the height of all the rows in a worksheet and then adjust them if a particular criterion is met? This tip ...

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

Discover MoreAdjusting the height of a row or range of rows is relatively easy in Excel. How do you adjust the height of those same ...

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

2020-07-26 04:16:59

Peter Atherton

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

2020-07-24 09:44:41

Kiwerry

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

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

2015-07-28 10:26:35

Ed

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?

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.

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

Copyright © 2022 Sharon Parq Associates, Inc.

## Comments