Microsoft KB Archive/79246

{| = Excel: SELECT.END Macro Example Is Incorrect =
 * width="100%"|

Last reviewed: November 30, 1994

Article ID: Q79246

SUMMARY
The macro example for SELECT.END on pages 212-213 in the &quot;Microsoft Excel Function Reference&quot; for version 3.0 does not work correctly. If the worksheet selection prior to running the macro contains cell(s) in Row 1 of the worksheet, a #NAME? error will result. Otherwise, the macro incorrectly includes the cell above the selection when creating the SUM formula.

Workaround
The errors are eliminated by adding 1 to the SelRows parameter as shown below:

Change

=FORMULA(&quot;=sum(R&quot;&BotRow&&quot;C:R&quot;&BotRow-SelRows&&quot;C)&quot;,&quot;R[2]C&quot;)

to

=FORMULA(&quot;=sum(R&quot;&BotRow&&quot;C:R&quot;&BotRow-SelRows+1&&quot;C)&quot;,&quot;R[2]C&quot;)

Steps to Reproduce Problem
 Type the example macro on a new macro sheet including the names in column A. Highlight the information in both columns and choose Create Names from the Formula menu. Select Left Column and select OK. Then select the top cell in the macro (B4 in the book) and choose Define Name from the Formula menu. Enter any name in the Name text box, choose the Command option, and choose OK. In a new worksheet, fill cells A1:A10 with the number 1.  Highlight A1:A10 on the worksheet and run the macro. The error #NAME? will appear in a cell two rows down from the selection. -or- Highlight A5:A10 on the worksheet and run the macro. The SUM formula created will be =SUM(A4:A10), which is incorrect. 