Microsoft KB Archive/113991

= Recorded AutoFit Selection Changes Entire Row or Column =

Article ID: 113991

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Excel 5.0 Standard Edition

-



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.

Additional query words: auto-fit XL5

Keywords: kbprogramming KB113991

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.