XL5: Recorded AutoFit Selection Changes Entire Row or Column

Last reviewed: September 2, 1997
Article ID: Q113991
The information in this article applies to:
  • Microsoft Excel for Windows, version 5.0

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: 5.00 auto-fit
Keywords : kbprg PgmOthr kbprg
Version : 5.00
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.