Microsoft KB Archive/75324

{|
 * width="100%"|

XL: Auto-Open Macro to Select Right Cell After Pressing ENTER

 * }

-

The information in this article applies to:


 * Microsoft Excel for Windows, versions 2.0, 2.01, 2.1, 2.10c, 2.10d, 3.0, 4.0, 4.0a, 5.0, 5.0c
 * Microsoft Excel for the Macintosh, versions 2.20, 2.2a, 3.0, 4.0, 5.0, 5.0a
 * Microsoft Excel for the Power Macintosh, versions 5.0, 5.0a
 * Microsoft Excel for OS/2, versions 2.2, 2.21, 3.0

-

SUMMARY
The &quot;More Information&quot; section of this article contains sample auto-open macros that position the active cell one cell to the right each time you press the ENTER key.

NOTE: If you want to use the Enter key on the Numeric keypad, replace the &quot;~&quot; portion of the code with &quot;{ENTER}&quot;.

MORE INFORMATION
Microsoft provides programming examples 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 article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

"http://www.microsoft.com/support/supportnet/overview/overview.asp"

Microsoft Excel Version 5.0
 On the Insert menu, point to Macro, and then click Module.  In the new module, type the following:      Sub auto_open Application.OnKey &quot;~&quot;, &quot;enter_move&quot; End Sub

Sub enter_move ActiveCell.Offset(0, 1).Activate End Sub  Save the file to your EXCEL\XLSTART directory.

Microsoft Excel Versions 4.0 and Earlier
This is similar to choosing Workspace from the Options menu and selecting the &quot;Move Selection After Enter&quot; check box, except that the active cell moves to the right instead of down.

  In a macro sheet, type the following: A1: Auto_Open

A2: =ON.KEY(&quot;~&quot;,&quot;Enter_Move&quot;)

A3: =RETURN

A4:

A5: Enter_Move

A6: =SELECT(&quot;RC[1]&quot;)

A7: =RETURN  Select cell A1. On the Formula menu, click Define Name. Select Command from the bottom of the dialog box, and then click OK. Select cell A5 and repeat step 3 above.</li> Save the file to your EXCEL\XLSTART directory.</li></ol>

The next time that Microsoft Excel is opened, the macro will run. When you press ENTER, the active cell will move to the right.

For more information about creating auto_open macros in Microsoft Excel version 5.0, follow these steps:


 * 1) On the Help menu, click Contents.
 * 2) In the Help contents window, choose Technical Support, and then choose Answers To Common Questions.
 * 3) Under the Creating and Running Macros section, choose the ANSWER to question 22 &quot;How Do I Set Up a Workbook So That It Runs a Macro Each Time I Open It?&quot;