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 SubSet Row Height
To set the row height using Excel VBA
Code:
Sub RowHeight()
Rows("1:1").RowHeight = 30
End SubAutofit Column Width
To autofit column width using Excel VBA
Code:
Columns("A:B").AutofitGet 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").ColumnWidthNote: 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


