Applies To
Range Object.
Description
Changes the width of the columns in the range or the height of the rows in the range for the best fit.
Syntax
object.AutoFit
object
Required. The range to apply the best fit to. Must be a row or a range of rows, or a column or a range of columns. Otherwise, this method generates an error.
Remarks
One unit of column width is equal to the width of one character of the Normal style.
See Also
ColumnWidth Property, RowHeight Property.
Example
This example changes the width of columns A through I on Sheet1 for the best fit.
Worksheets("Sheet1").Columns("A:I").AutoFit
This example changes the width of columns A through E on Sheet1 for the best fit, based only on the contents of cells A1:E1.
Worksheets("Sheet1").Range("A1:E1").Columns.AutoFit