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 post, you’ll learn how to Find Blank cells in excel so that you can remove or delete the blank cells form...
In this article, you’ll learn what is a Gauge Chart in Microsoft Excel. Also, you will learn how to add...
Microsoft Excel provides a shortcut for the users to move columns in excel using two different ways – using Shift...