Syntax

expression.AutoFit

expression A variable that represents a Range object.

Return Value
Variant

Remarks

The Range object must be a row or a range of rows, or a column or a range of columns. Otherwise, this method generates an error.

One unit of column width is equal to the width of one character in the Normal style.

Example

This example changes the width of columns A through I on Sheet1 to achieve the best fit.

Visual Basic for Applications
Worksheets("Sheet1").Columns("A:I").AutoFit

This example changes the width of columns A through E on Sheet1 to achieve the best fit, based only on the contents of cells A1:E1.

Visual Basic for Applications
Worksheets("Sheet1").Range("A1:E1").Columns.AutoFit
Adapt size of columns to fit the data. adjust row height and column width to accomodate different font sizes auto fit Auto Fit Method AutoFit autofit method Automatically resize my columns to fit numbers. Can my program automatically create multiline rows?

See also: