How to Set Column Properties in Excel VBA?

In this post, you’ll be learning how to set column properties in your excel spreadsheet programmatically using Excel VBA.

How to Set Column Properties in Excel VBA?

Excel allows you to alter the row and column properties like height, width etc. Let’s look at the properties in detail.

Set Column Width

To set the column width using Excel VBA

Code:

Sub Column_Width()
    Columns("A:D").ColumnWidth = 30
End Sub
How to Set Column Properties in Excel VBA?

Set Row Height

To set the row height using Excel VBA

Code:

Sub RowHeight()
    Rows("1:1").RowHeight = 30
End Sub
How to Set Column Properties in Excel VBA?

Autofit Column Width

To autofit column width using Excel VBA

Code:

Columns("A:B").Autofit
How to Set Column Properties in Excel VBA?

Get Row Height and Column Width

Column Width

To obtain the column width of a column using Excel VBA:

Code:

dim iColumnWidth as long
iColumnWidth = columns("a").ColumnWidth

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

Row Height

To obtain the Row height of a column using Excel VBA

Code:

dim iRowHeight as long
iRowHeight = rows("1").RowHeight

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this article, you will learn about the SKEW.P function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the SKEW function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the RANK.EQ function, the formula syntax and usage of the function in Microsoft...
  • Excel
  • November 23, 2021