Microsoft KB Archive/72137

{| = Macro Errors May Occur if an Object Is Currently Selected =
 * width="100%"|

Last reviewed: November 2, 1994

Article ID: Q72137

SUMMARY
An error might be encountered in a macro if you attempt to manipulate the worksheet after selecting an object. A dialog box displays, stating that there is an error in the macro at the cell where the command tries to adjust the worksheet.

MORE INFORMATION
For example, the following macro selects a button on a worksheet and then attempts to adjust the row heights of a selected range. The macro will generate an error at cell A3.

A1: =SELECT(&quot;button 1&quot;) A2: =FORMAT.SIZE(72,36,!C5) A3: =ROW.HEIGHT(0,&quot;r15:r20&quot;) A4: =RETURN However, if you place the command in A3 to run first, the macro will run correctly. Another workaround is to follow the Select command with a second Select command that selects any cell on the worksheet. A1: =ROW.HEIGHT(0,&quot;r15:r20&quot;) A2: =SELECT(&quot;button 1&quot;) A3: =FORMAT.SIZE(72,36,C5) A4: =RETURN

-or-

A1: =SELECT(&quot;button 1&quot;) A2: =FORMAT.SIZE(72,36,C5) A3:= SELECT(!A1) A4: =ROW.HEIGHT(0,&quot;R15:R20&quot;) A5: =RETURN This error occurs because objects are on a different layer than the worksheet layer. Although the worksheet is the active document, the object layer is the active layer when the worksheet manipulation is attempted. Other commands may also cause macro errors if attempted when an object is the current selection. Some commands, such as the Formula command will work fine.