Automatic Row Height for Wrapped Text
Please Note: This article is written for users of the following Microsoft Excel versions: 2007 and 2010. 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.
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.
You can find additional information about this issue in the Microsoft Knowledge Base:
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:
For Each CL In UsedRange
If CL.WrapText Then CL.Rows.AutoFit
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.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10735) applies to Microsoft Excel 2007 and 2010. You can find a version of this tip for the older menu interface of Excel here: Automatic Row Height for Wrapped Text.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
Comments for this tip:
Tim White 10 Jul 2015, 11:54
These tips did not work for me. I didn't try the macro...just seemed to be too much work to resolve something that should be an easy fix. However, I discovered another possible exception to the defaults Mr. Wyatt mentioned--the COLUMN adjustment.
In my case, I did not have any merged cells. Setting the row height to auto-adjust (or double-clicking the boundary) did not help. What I found was that if double-clicked the column boundary to auto-adjust, then (by accident) manually adjusted it, some text strings would now longer auto adjust the row height (typically the shorter text strings). When I double-clicked the column boundary or set it to "auto", my text wrap worked properly again.
Joyce Miller 17 Apr 2015, 16:31
I'm getting a error even when I dim the CL. Can someone help?
CB 06 Mar 2015, 08:55
Excellent tutorial. Thanks for the help.
Grateful Person 03 Mar 2015, 17:31
Thank you so much, the autofit row height was exactly the feature that I needed.
Todd 20 Nov 2014, 11:48
Thank you for this article!! I was stumped as to why row height would no longer auto adjust in a series of templates. Your article spared me the dreaded task of having to recreate a number of templates to restore this auto row height formatting.
Marsha 17 Nov 2014, 13:47
The comment by Deborah Bryant regarding copying and pasting the entire sheet into a new one worked for me. Adjusting the height wasn't working. Thanks!!!!
Kristin 30 Sep 2014, 14:17
I tried this in Excel 2013 and my text is still being cut off. In one row, if I manually drag the row to fit, the row would be 259 high, however, when I "autofit" it, it shrinks to 229 and cuts off my text. This cell has 1,301 characters, counting spaces.
I have 216 rows, word wrap is on, and some of the cells in my spreadsheet are merged.
Also, other commenters, I found a tip from another page that says not to add this as a new macro, rather, from the Developer tab, open "View Code" from the Controls area, then paste this in. Then you can run the macro.
Deborah Bryant 03 Jun 2014, 17:02
What's even easier? Copy the whole sheet, paste it into a new worksheet, and voila, the row height auto function works correctly.
awyatt 23 May 2014, 18:46
The author (me) doesn't answer all the questions. I do answer some, as you can see if you look down further in this comment list.
Comments are largely for discussion among all readers of the tips.
Steve 23 May 2014, 17:40
Why aren't any of the questions in the comments answered here by the author?
Siva.SA 08 Apr 2014, 07:37
why row height automatically adjust (409.5)in excel 2010?
Bryan 01 Dec 2013, 07:32
Allen stated that the variable is automatically defined as a variant. This is bad programming practice, and is not correct if you (as a good programming practice) have the "require variable declaration" box checked or use Option Explicit, as it seems many people are.
You should dimension the variable as a Range object by adding the following line to the code:
Dim CL As Range
Peter Vella 01 Dec 2013, 04:37
s per another person commenting here, do we need to define "CL" or why isn't it recognized?
Jiju 25 Jun 2013, 12:43
I came to know that them max allowed height for a cell is 409 so if you have wrapped text above that range it will be hidden within the cell..The only work arounf is increase the width of that cell so all text shows
Nancy 21 May 2013, 12:25
What do you do if the cell in which you are wrapping text is actually merged with another cell in Excel 2010?
Brent Olund 19 Jun 2012, 11:08
In an Excel 2010 sheet with ~1,700 rows of cells with wrapped text, but no merged cells, certain rows no longer auto-fit their height to the wrapped text their cells contain. Possibly they were manually resized previously.
In attempting to run your macro (to reset all row height sizing to automatic notwithstanding the wrapped text), I get a Run time error '13' type mismatch, then when I open the Debugger the first row of code "For Each CL in UsedRange" is highlighted yellow.
As per another person commenting here, do we need to define "CL" or why isn't it recognized?
Terry Fenner 20 Feb 2012, 17:54
I've tried everything - I'm using VLOOKUP to import cells from 1 sheet to another sheet and the rows with the imported cell will not auto-expand, no matter what so I tried your macro. But, when I ran it, it said that UsedRange was empty - do I need to create a range to use the macro.
awyatt 01 Dec 2011, 10:28
The only variable in the macro is CL, which is automatically defined as a variant. Should work fine.
Tom Blancke 01 Dec 2011, 09:20
About the quick litte macro :
how do you have to define the variables, because the macro doesn't seem to work without them?
Leave your own comment: