Table of Contents
VBA (Visual Basic for Applications) is a programming language used to automate tasks in Microsoft Office applications, such as Excel. One common task users may need to perform is changing the row height in a spreadsheet. This can be done easily using VBA by utilizing the “RowHeight” property of the Range object. This property allows the user to specify the exact height of the row in points.
To change the row height using VBA, the user must first select the row(s) they wish to modify. Then, they can use the “RowHeight” property to set the desired height. For example, if the user wants to set the height of Row 1 to 25 points, they would use the following code:
Range(“1:1”).RowHeight = 25
Similarly, if the user wants to set the height of multiple rows (such as Rows 1 to 5), they can use the same code but specify the range as “1:5” instead of just “1:1”.
This method of changing row height using VBA can be useful for various tasks, such as formatting a large dataset or creating a more visually appealing spreadsheet. It can also be combined with other VBA commands to perform more complex actions, such as automatically adjusting row heights based on the content of cells. By utilizing the “RowHeight” property in VBA, users can efficiently and effectively customize the appearance of their Excel worksheets.
Change Row Height in VBA (With Examples)
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 SubThis 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:

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 SubWhen 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 SubWhen 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:
Cite this article
stats writer (2024). How can I change the row height using VBA, and what are some examples of how to do so?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-change-the-row-height-using-vba-and-what-are-some-examples-of-how-to-do-so/
stats writer. "How can I change the row height using VBA, and what are some examples of how to do so?." PSYCHOLOGICAL SCALES, 24 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-change-the-row-height-using-vba-and-what-are-some-examples-of-how-to-do-so/.
stats writer. "How can I change the row height using VBA, and what are some examples of how to do so?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-change-the-row-height-using-vba-and-what-are-some-examples-of-how-to-do-so/.
stats writer (2024) 'How can I change the row height using VBA, and what are some examples of how to do so?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-change-the-row-height-using-vba-and-what-are-some-examples-of-how-to-do-so/.
[1] stats writer, "How can I change the row height using VBA, and what are some examples of how to do so?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I change the row height using VBA, and what are some examples of how to do so?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
