Learn Programming and technology with ease @ developerpublish.com

HomeMicrosoft OfficeExcelHow to Set Column Properties in Excel VBA?

# 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```

### Set Row Height

To set theÂ row heightÂ using Excel VBA

Code:

```Sub RowHeight()
Rows("1:1").RowHeight = 30
End Sub```

### Autofit Column Width

To autofit column width using Excel VBA

Code:

`Columns("A:B").Autofit`

### 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```

Share:

### You May Also Like

#### SKEW.P Function in Excel

In this article, you will learn about the SKEW.P function, the formula syntax and usage of the function in Microsoft...

#### SKEW Function in Excel

In this article, you will learn about the SKEW function, the formula syntax and usage of the function in Microsoft...

#### RANK.EQ Function in Excel

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