Return to VBA Code Examples

VBA Set Column Width or Row Height

This tutorial will demonstrate how to set row height and column widths using VBA.

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.

VBA Programming | Code Generator does work for you!

Autofit Row Height

You can also autofit row heights using a similar method:

Set Cell Width

You can also adjust column widths by referencing a cell:

Set Cell Height

Or adjust row heights by referencing a cell:

Tired of Searching for VBA Code Examples? Try AutoMacro!

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.

VBA Programming | Code Generator does work for you!

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