Press Enter and Stay in the Same Cell in Excel

By default, whenever you’re in a cell in Excel and hit the Enter/Return key, the cursor would go down one cell.

In most cases, this is what you want (especially during data entry when you want to move to the next cell below)

But I’ve also come across many scenarios where users do not want to move the cursor to the next cell. They want the cursor to remain on the same cell when they hit the Enter key.

Now there are two broad scenarios where this is required:

  1. You hit the Enter key and the cursor stays on the same cell
  2. you want to hit the enter key and want to move to the next line in the same cell so that you can have multiple lines of data in a cell in Excel

In this tutorial, I will show you how to do both of these things, so that when you hit the enter key the cursor remains on the same cell.

Keyboard Shortcut to Keep the Same Cell Active When you Hit the Enter/Return Key

If all you want is the cursor to remain on the same cell when you hit the enter key, the easiest way would be to use the below keyboard shortcut

Control + ENTER

To use this keyboard shortcut, hold the ALT key and then press the Enter key.

This keyboard shortcut works just like hitting the Enter key, while keeping the cursor in the active cell.

Bonus Shortcut: If you use SHIFT + ENTER, the cursor would move one cell above.

VBA Code to Change Cursor Movement After the Enter Key

While the keyboard shortcut is great, if you want to change the default movement of the cursor when the enter key is hit, you can do that with a very simple one-line VBA code.

Once the VBA code is executed, whenever you hit the Enter key, the cursor stays on the same cell and will not move anywhere

Make the Change In All Excel Files (the Entire Excel Application)

Below is the VBA macro code to do this:

Application.MoveAfterReturn = FALSE

Below are the steps to use this VBA macro code:

  1. Open any Excel workbook (or activate any existing open workbook)
  2. Click the Developer tab (check this if you can’t see the developer tab in the ribbon)
  3. Click on Visual Basic (this opens the VB editor)
Click in Visual Basic
  1. Click the View option in the menu
  2. Click on Immediate Window
Click on Immediate Window
  1. Copy the above code and paste it into the ‘Immediate Window’
Paste the code in the Immediate Window
  1. Place the cursor at the end of the code line and hit Enter (this executes that line of code)
  2. Close the VB Editor

The above steps would run this line of code.

Now, when you are working on a worksheet in Excel and you hit the Enter key, it will keep you in the same cell and not move you to the cell below.

In the above code, we have changed the MoveAfterReturn property and set it to FALSE.

This property is TRUE by default, which means that whenever you hit the Enter key in the Excel application, it moves to the cell below.

By setting this property to FALSE, we had asked Excel not to move the cursor when we hit Enter.

One very important thing to know here is that this change will be applied to the entire Excel application. so even if you close the current workbook and open a new or any other existing workbook, this change would remain in place (unless you revert it by setting the MoveAfterReturn property to TRUE)

To revert this change so that the cursor starts moving to the cell below when you hit the enter key, you need to follow the same steps shown above and use the below VBA code instead:

Application.MoveAfterReturn = TRUE

Make the Change In Specific Excel Files

If you want the cursor to remain on the same cell when you hit enter in only some specific workbooks, and not the entire Excel application, you can do that as well using a simple VBA code.

To do this, you have to ensure that MoveAfterReturn is set to FALSE in only that specific workbook, and it’s TRUE in all the other workbooks.

And there is a very smart way to do this in Excel.

First, let me give you the VBA code that will do this, and then I will explain where to put this code and how to use this.

'This code is developed by Scott from https://spreadsheetplanet.com
Private Sub Workbook_Activate()
Application.MoveAfterReturn = False
End Sub

Private Sub Workbook_Deactivate()
Application.MoveAfterReturn = True
End Sub

Below are the steps to place this code in the workbook where you want the cursor to remain on the active cell when you hit the Enter key:

  1. Open the Excel workbook where you want to apply this
  2. Click the Developer tab
  3. Click on Visual Basic (this opens the VB editor)
Click in Visual Basic
  1. In the ‘Project Explorer’ pane, double-click on the ThisWorkbook object (If you don’t see the Project Explorer, click on View and then click on Project Explorer)
Thisworkbook in VB Editor
  1. Copy and Paste the above VBA code in the ThisWorkbook code window
Copy and paste the code in the ThisWorkbook code Window
  1. Save the Workbook as a .xlsm (macro-enabled file). The option comes when you save the file (in the Save as Type drop-down in the Save as dialog box)

Once you have added this code to one specific workbook, the MoveAfterReturn property will be set to FALSE only in this specific workbook and will remain TRUE in all the other workbooks.

So when you open/activate this specific workbook and hit the Enter/Return key when working on any cell in the worksheet, the cursor will stay on the same cell.

But for any other workbook, the cursor would move to the cell below.

Let me also quickly explain what happens with this code and how it works.

The Private Sub Workbook_Activate() part of the code is only run when you activate that specific workbook. So, as soon as you open or activate that workbook, the MoveAfterReturn property is set to FALSE.

As soon as you deactivate this workbook (which could be by moving to any other workbook or application), the Private Sub Workbook_Deactivate() part of the code is executed, which sets the MoveAfterReturn property to TRUE.

This way, we are only changing the MoveAfterReturn property in that specific workbook, and we revert it back to its default setting (which is true) as soon as this specific workbook is deactivated.

Entering New Line In The Same Cell

Another common scenario where you may want to remain on the same cell when you hit enter is when you want to have multiple lines in the same cell.

By default, as soon as you hit the Enter key, whatever you have entered in the cell remains, and the cursor moves to the next cell.

But what if you want to have multiple lines in the same cell (as shown below).

You can achieve this easily by using the below keyboard shortcut

ALT + ENTER

To use this keyboard shortcut, enter any text that you want to have as the first line in the cell, place the cursor at the end of the line, and then use the above keyboard shortcut by holding the alt key and then pressing the enter key.

ALT + ENTER works as a carriage return where it starts a new line in the same cell.

So, these are some of the methods that you can use to stay in the same cell when you hit the Enter or Return key.

If you only need to do this occasionally, you can use the keyboard shortcut CONTROL + ENTER, but if you need this functionality to be more permanent, you can use the VBA code method.

And finally, if you want to start a new line in the same cell in Excel, you can use the keyboard shortcut ALT + ENTER

I hope you found this Excel tutorial helpful.

Other Excel guides that may also be useful:

I am a huge fan of Microsoft Excel and love sharing my knowledge through articles and tutorials. I work as a business analyst and use Microsoft Excel extensively in my daily tasks. My aim is to help you unleash the full potential of Excel and become a data-slaying wizard yourself.

3 thoughts on “Press Enter and Stay in the Same Cell in Excel”

  1. I’d like to have:
    Application.MoveAfterReturn = FALSE
    apply to only one cell on a specific sheet.
    I’m thinking if I detect the cell below being selected, then move the cursor back up.

    Reply
  2. I had been thinking of detecting a cell entry, and then putting the cursor back. Looking at the problem differently, i.e. not letting the cursor leave the cell, did the trick. Simple code behind the sheet:

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Application.Intersect(Range(“SSRowNum”), Range(Target.Address)) Is Nothing Then Exit Sub
    Range(“SSRowNum”).Select

    End Sub

    Reply
    • I have improved my macro. On my sheet, alongside the selected cell, is a macro button. At times, from other sheets, I like to put a number here and run that macro. But if not on the same sheet, the above macro fails on Select.

      There is a simple fix. You have to set a Macro Running Flag global variable:

      Public MRFlag As Boolean

      In the above macro add:

      If MRFlag Then Exit Sub

      Before the Select. Then in the macro that puts a number into the input cell, you surround that with

      MRFlag = True
      Range(“SSRowNum”).Value = xx
      MRFlag = False

      Reply

Leave a Comment