'Move the cursor to the right next cell, rather than the cell underneath
This is what I want to achieve with the code further down: If I use the RETURN key, the cell right next to the current cell should be selected, rather than the cell underneath. When I execute the code (i.e. I change between two different worksheets, the cursor moves from the current selected cell to the right next one. When then I use RETURN, I get the message as in the attached image: "Cannot run the macro 'PathToMacro\MacroName'!TRUE: The macro may not be available in this workbook or all macros may be disabled." What I want to achieve is this: Change the behaviour of the RETURN key so that not the underneath cell, but the cell right to the currently selected cell is selected.
Please help with this. Thank you.
Option Explicit
Sub getNextCell()
activeCell.Offset(0, 1).Activate
End Sub
Private Sub Worksheet_Activate()
Dim activeCell As Range
Set activeCell = Selection
Application.OnKey "{RETURN}", Cells(activeCell.row, activeCell.column + 1).Select
End Sub
Private Sub Workbook_Open()
Application.OnKey "{RETURN}", Cells(activeCell.row, activeCell.column + 1).Select
End Sub
Private Sub Worksheet_Deactivate()
Application.OnKey "{RETURN}"
End Sub
Solution 1:[1]
This is the answer to my question: The procedures are specific to the sheet. As the sheet is entered, the cursor moves to the right As the sheet changes to another sheet, regular behaviour is restored!
' move cursor to the right upon ENTER key
Private Sub Worksheet_Activate()
Application.MoveAfterReturnDirection = xlToRight
End Sub
' return to default behaviour
Private Sub Worksheet_Deactivate()
Application.MoveAfterReturnDirection = xlDown
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Michaelinscarbororough |
