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

Last reviewed: December 1, 1997
Article ID: Q75324

The information in this article applies to:
  • Microsoft Excel for Windows, versions 2.x, 3.0, 4.0, 4.0a, 5.0, 5.0c
  • Microsoft Excel for the Macintosh, versions 2.x, 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 and 3.0

SUMMARY

The "More Information" 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 "~" portion of the code with "{ENTER}".

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 engineers 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/refguide/default.asp

Microsoft Excel Version 5.0

  1. On the Insert menu, point to Macro, and then click Module.

  2. In the new module, type the following:

          Sub auto_open()
             Application.OnKey "~", "enter_move"
          End Sub
    
          Sub enter_move()
             ActiveCell.Offset(0, 1).Activate
          End Sub
    
    

  3. 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 "Move Selection After Enter" check box, except that the active cell moves to the right instead of down.

  1. In a macro sheet, type the following:

          A1:     Auto_Open
          A2:     =ON.KEY("~","Enter_Move")
          A3:     =RETURN()
          A4:
          A5:     Enter_Move
          A6:     =SELECT("RC[1]")
          A7:     =RETURN()
    
    

  2. Select cell A1.

  3. On the Formula menu, click Define Name. Select Command from the bottom of the dialog box, and then click OK.

  4. Select cell A5 and repeat step 3 above.

  5. Save the file to your EXCEL\XLSTART directory.

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 "How Do I Set Up a Workbook So That It Runs a Macro Each Time I Open It?"

REFERENCES

"Microsoft Excel User's Guide 2," version 4.0, pages 260-262 "Microsoft Excel Function Reference," version 4.0, pages 302-304 "Microsoft Excel User's Guide," version 3.0, pages 622-624 "Microsoft Excel Function Reference," version 3.0, pages 165-167


Additional query words: 2.0 2.00 2.01 2.1 2.10 2.2 2.20 2.21 3.00 4.00
4.00a 5.00
Keywords : kbcode kbmacro PgmHowto PgmOthr
Version : WINDOWS: 2..0,3.0,4.0,4.0a,5.0,5.0c; MACINTOSH: 2.0,3.0,4.0,5.0,5.0a
Platform : MACINTOSH OS/2 WINDOWS
Issue type : kbhowto


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: December 1, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.