Column Widths


ColumnWidth Property

The ColumnWidth property returns or sets the width of the columns in the specified range,
The return value is in units which represents the number of characters which can be displayed in the column.
Each unit represents the width of one character used in the Normal style.
For variable or proportional size fonts (eg Arial, Verdana) the width of the zero character "0" is used.

Columns("A:D").ColumnWidth = 20 

Width Property

The Width property can be used to return the column width in points.
The relationship between Width and ColumnWidth is a little odd.


Changing the Width


Selection.ColumnWidth = 10 
Range("C5").ColumnWidth = 14

Dim icolno As Integer 
For icolno = 1 to 10
   Debug.Print icolno & " - " & Cells(1,icolno).ColumnWidth
Next icolno

Obtaining the Width


If all the columns in the range do not all have the same width then Null is returned.

Dim iColumnWidth As Integer 
iColumnWidth = Columns("A").ColumnWidth 'this is in units

Dim iWidth As Integer 
iWidth = Columns("A").Width 'this is in points

AutoFit Columns

The AutoFit method changes the width of the column(s) to obtain the best fit for the columns.
This changes the ColumnWidth accordingly.

Columns("A:H").EntireColumn.AutoFit 
Range("F4").CurrentRegion.EntireColumn.AutoFit

1 point = 1/72 inches
1 point = 35/100 millimeters



Blank new worksheet
Default - 8.43 (64 pixels_
?? - 8.50 (56 pixels)



© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext