VBA Set Column Width or Row Height

Associated Files Download Links


Excel Row heights and Columns widths can be changed in VBA by setting the .RowHeight and .ColumnWidth properties.

Set Column Width with VBA

Macro to set the column width of Columns A to E:

Set Row Height with VBA

Macro to set the row height of Row 1:

Autofit Column Width

Excel offers the ability to “Autofit” column widths. This feature adjusts the column width so that the column(s) is wide enough to fit all text found in that column.
vba autofit column width
To Autofit column widths in VBA:

We wrote more about this in another article on how to Autofit a Column from VBA, including how to Autofit all used columns.

Autofit Row Height

You can also autofit row heights using a similar method:

Set Cell Height

Or adjust row heights by referencing a cell:

Obtain Column Width

To obtain the column width of a column:

Note: This will return Null if all columns in the range do not have the same width.

Obtain Row Height

Similarly, you can obtain the row height:

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

vba set column width

Learn More!


<<Return to VBA Examples

Did you find this VBA tutorial useful? Then share it with your friends and colleagues: