Recorded AutoFit Selection Changes Entire Row or Column (113991)
The information in this article applies to:
- Microsoft Excel for Windows 5.0
This article was previously published under Q113991 SYMPTOMS
In Microsoft Excel 5.0, when you record a macro that includes the AutoFit
Selection command, the resulting macro will apply the AutoFit command to
the entire row or column rather than to the desired selection.
CAUSE
This behavior occurs when you record the macro using the Visual Basic
language. The recorded Visual Basic code uses the EntireColumn property to
qualify the AutoFit method. For example, if you are using the macro
recorder, and you select a cell, and use the column AutoFit feature, the
following command is recorded:
Selection.EntireColumns.AutoFit
WORKAROUND
To work around this behavior, you can modify the recorded command, or add
the following command to your Visual Basic procedure to perform an AutoFit
on the current selection instead of the entire column.
Sub AutoFitColumnSelection()
Selection.Columns.Autofit
End Sub
To perform the AutoFit on a row rather than a column, use the Rows method
instead of the Columns method as in the following example:
Sub AutoFitRowSelection()
Selection.Rows.Autofit
End Sub
Microsoft provides examples of Visual Basic procedures for
illustration only, without warranty either expressed or implied,
including but not limited to the implied warranties of merchantability
and/or fitness for a particular purpose. This Visual Basic procedure
is provided 'as is' and Microsoft does not guarantee that it can be
used in all situations. Microsoft does not support modifications of
this procedure to suit customer requirements for a particular purpose.
STATUS
Microsoft has confirmed this to be a problem in the Microsoft products
listed at the beginning of this article. This problem was corrected in
Microsoft Excel for Windows version 5.0c.
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbProgramming KB113991 |
---|
|