Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. 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: Setting Row Height in a Macro.

Setting Row Height in a Macro

by Allen Wyatt
(last updated August 31, 2018)

3

It is not unusual to use macros to process data and format output in an workbook. If you use macros to do this type of work, you may be interested in changing the height of a row using a macro. If so, you should pay attention to the RowHeight property. This property, when applied to a Row object, indicates the height of the row in points.

For instance, the following code snippet steps through the rows in a selection and sets the height of each row to 36 points (one-half inch):

For Each r In ActiveWindow.RangeSelection.Rows
    r.RowHeight = 36
Next r

If you prefer not to step through each of the rows, you could use the following single line to adjust the row height:

Selection.RowHeight = 36

Either approach sets the height of all the rows that were selected when the code is executed. If you want your macro to adjust a specific range of rows, then you can specify the rows directly in the code:

ActiveSheet.Rows("3:34").RowHeight = 36

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 (9239) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Setting Row Height in a Macro.

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

Creating an AutoText List

The AUTOTEXTLIST field is one of those esoteric fields that you may know nothing about. The cool thing it does is allow ...

Discover More

Preventing Straggling Heads

Undoubtedly you will want to format your document so that headings stay with the paragraph that follows the heading. ...

Discover More

Finding Long Lines

Word is very dynamic in how it "flows" text from one line to another and one page to another. In most cases we are ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Switching Windows in a Macro

When you have multiple workbooks open at the same time, Excel allows you to easily switch between those workbooks. How ...

Discover More

Converting HSL to RGB

When working with colors in Excel you can specify them using either RGB or HSL values. Converting from HSL to RGB can be ...

Discover More

Friendly and Informative Error Handling

When creating macros, it is helpful to know what is going on within the macro itself in case an error crops up. Here's ...

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 eight more than 6?

2018-09-04 07:20:33

Andrea Carr

Thanks, Gregg

I'll try t by at out soon, but it sure looks like it would work well.

Andrea


2018-09-03 12:08:49

gregg

Hi Andrea,

I am building a project management tool and was wanting to set row heights as needed for wrapped cells. With some help, I came up with this code which works without any problems I've seen

'adjust row height if wraps
Rows(ActiveCell.row).EntireRow.Select
Dim CL As Range
'Range.CurrentArray.Select
Range("F" & (ActiveCell.row)).Select
If ActiveCell.WrapText Then Rows(ActiveCell.row).AutoFit
If ActiveCell.WrapText Then Rows(ActiveCell.row).AutoFit
With Range("F" & ActiveCell.row)
.RowHeight = .RowHeight + 5
End With

Range("G" & (ActiveCell.row)).Select
If ActiveCell.WrapText Then Rows(ActiveCell.row).AutoFit
With Range("G" & ActiveCell.row)
.RowHeight = .RowHeight + 5
End With


2018-08-31 07:32:19

Andrea Carr

I've enjoyed your tips for years and learned much about
Excel. So thank you.

I think a follow up tip about this subject would be great. It would be great to learn more about the interaction between row height and wrap text. The auto format row height and wrap text often do not work well together. So I wonder if setting row height in VBA is a better way.

Andrea


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.