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: Automatic Row Height for Wrapped Text.

Automatic Row Height for Wrapped Text

by Allen Wyatt
(last updated October 31, 2020)

5

Jordan formatted some cells in his worksheet to wrap text within them. Even though the text in the cells wraps, Excel won't automatically adjust the row height to show all the wrapped text. Jordan wonders if there is a way to "reset" the row so that Excel will adjust its height based on the text being wrapped within the cells.

By default, when you wrap text within a cell, Excel automatically adjusts row height so that all the text in the cell is visible. There are only two exceptions to this default:

  • The cell in which you are wrapping text is actually merged with another cell.
  • The height of the row in which the cell is located was previously changed.

In Jordan's case, there are no merged cells in the problem row. This leaves us with the second exception—it would appear that the height of the row in which the cell is located was explicitly set before wrapping was turned on in some of the row's cells.

In this case, the solution is simple: Reset the row height. There are actually a couple of ways you can do this. First, you could select the row and then double-click the "boundary" between the row and an adjacent row. With the row selected, take a look at the row header, to the left of column A. This area contains a row number, and the "boundary" you need to double-click is between this row number and the next row number.

It can be a bit tricky to get the mouse pointer in the correct location to do the double-clicking, so an approach I prefer is to select the row and display the Home tab of the ribbon. In the Cells group there is a Format tool; I click it and then choose AutoFit Row Height. This allows Excel to determine the appropriate row height based on the contents of the row. If a cell in the row has wrapping turned on, then the row height will automatically adjust to display the information in the cell.

If you have quite a few rows that contain cells with wrapping turned on, and the height of none of the rows is adjusting, then you may be interested in a quick little macro that can do the adjustment for you:

Sub AutofitRows()
    Dim c As Range

    For Each c In ActiveSheetUsedRange
        If c.WrapText Then c.Rows.AutoFit
    Next c
End Sub

The macro steps through all the cells in a worksheet, and if the cell has wrapping turned on, it sets the AutoFit property of the row in which the cell is located.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10735) 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: Automatic Row Height for Wrapped 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

Printing Comments from a Macro

Need to print the comments you've added to a document? You can do it manually or you can have your macro do the printing. ...

Discover More

Customizing File Explorer's Display

File Explorer is a powerful utility to use for navigating among your files and folders. And it can be customized a great ...

Discover More

Automatically Protecting After Input

Do you want user-entered data to be immediately protected so that it cannot be changed? This can be done relatively ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

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

Detecting Hidden Rows

Excel allows you to easily hide rows in a worksheet, so their contents are not visible. Figuring out how to detect where ...

Discover More

Setting Row Height

When you enter information into a row on a worksheet, Excel automatically adjusts the height of the row based on what you ...

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}] 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 1 + 9?

2021-01-31 04:07:15

Rohn S, MVP 2012-2018

Hi John:
Maybe you are right. But the macro works the way it is to do what I want, so I'm not going to mess with success <g> .

Play with it and let us know what find.


2021-01-30 16:06:04

John Mann

@Ron S
I'm a raw novice with macros, so maybe I'm not understanding something in your second version. If I understand correctly what you are doing, it's to both apply the "wrap text" property, and the "Automatic Row Height".

If I'm reading you macro correctly (big If), then you test for if the text is wrapped and if so then apply Autofit. Later you set the wrap text. Shouldn't the wrap text be set first?

Please note that at this point I haven't done any testing - just read the tip.

I've been having trouble with these features in some tables (formated as such) in Excel 2010. I've set the wrap text property for entire columns, and likewise the Autofit Row Height for the entire columns (from the ribbon), but sometimes find new entries don't have the Auto Fit Row Height applied, and have to do it again. Macros of this type, run from my rather long QAT would be useful.

This is one tip which will be printed and added to my collection of printed tips


2020-11-03 13:11:51

william driskell

shortcut - if you click in upper left corner of the sheet's margin to "select entire sheet," then click any row's upper/lower edge in the left margin, you will auto-adjust the entire sheet instead of a single row.
I usually like to auto-adjust all row heights after widening a column for some awkwardly wrapped text content. Must be some pysch phenomena but I find it easier to visually scan through data when they're all in similar cells --or maybe it's just OCD showing up in formatting...


2020-11-01 07:43:44

Ron S MVP

I've since tweaked the macro some more to now apply the WrapText attribute.

Sub AutoFitRowHeight()
' https://excelribbon.tips.net/T010735_Automatic_Row_Height_for_Wrapped_Text.html
'
' Select the area to be affected
' Loop through all rows in current sheet, turn on AutoFit Row Height attribute
' Turn on Wrap attribute to resize rows
'
Dim c As Range

For Each c In ActiveSheet.UsedRange
If c.WrapText Then c.Rows.AutoFit
Next c

With Selection
.WrapText = True
End With

End Sub

I tried adding c.Rows.WrapText=True inside the "IF", but it didn't work. I had to move as above.


2020-10-31 10:30:13

Ron S MVP

Oops, typo:
For Each c In ActiveSheetUsedRange

Should be:
For Each c In ActiveSheet.UsedRange

This is definitely something I didn't know I needed. But now that I have it, it is on my QAT now and I'll be using it, A LOT!


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.