How to Change Row Height in VBA?

To change the row height in VBA, you can use the RowHeight property to set the row height to any value you want in the worksheet. You can use this property to make a row taller, or shorter, depending on the value you set. You can also use the Autofit option to automatically adjust the row height based on the content of the cells within the row. Finally, you can use the EntireRow.RowHeight property to adjust the row height for multiple rows at once.


You can use the following methods to change the row height in Excel using VBA:

Method 1: Change Height of One Row

Sub ChangeRowHeight()
Rows(3).RowHeight = 40
End Sub

This particular macro changes the height of the third row to 40.

Note: The default row height in Excel is 14.4.

Method 2: Change Height of Multiple Rows

Sub ChangeRowHeight()
Rows("1:5").RowHeight = 40
End Sub

This particular macro changes the height of each row from one through five to 40.

Method 3: Auto Adjust Height of Multiple Rows

Sub ChangeRowHeight()
Rows("1:8").AutoFit
End Sub

This particular macro automatically adjusts the height of each row from one through eight to be as tall as necessary to display the tallest text in each row.

The following examples show how to use each of these methods in practice with the following dataset in Excel:

Related:

Example 1: Change Height of One Row

We can create the following macro to change the height of the third row to 40:

Sub ChangeRowHeight()
Rows(3).RowHeight = 40
End Sub

Notice that only the height of the third row has been increased to 40 while the height of all other rows remained the same.

Example 2: Change Height of Multiple Rows

We can create the following macro to change the height of each row from one through five to 40:

Sub ChangeRowHeight()
Rows("1:5").RowHeight = 40 
End Sub

When we run this macro, we receive the following output:

Notice that the height of each of the first five rows has increased to 40 while the height of all other rows remained the same.

Example 3: Auto Adjust Height of Multiple Rows

We can create the following macro to automatically adjust the height of each of the first eight rows to be as tall as necessary to display the tallest text in each row:

Sub ChangeRowHeight()
Rows("1:8").AutoFit
End Sub

When we run this macro, we receive the following output:

Notice that the height of each row has automatically been adjusted to be as tall as necessary to display the tallest text in each row:

x