In excel when in a cell and you press enter, the selection drops to the next cell below.…
- User
In excel when in a cell and you press enter, the selection drops to the next cell below. If the next cell below has a selection change event, it is automatically triggered. How can I prevent this automatic trigger of the selection event when the selection is moved to the cell below when pressing enter on the cell above.
- Assistant
You can prevent the automatic trigger of the cell selection event by disabling the Application.EnableEvents property before moving the selection to the next cell. Here's an example code that you can use:
vbaPrivate Sub Worksheet_SelectionChange(ByVal Target As Range) 'Your selection change event code here MsgBox "Selection changed!" End Sub Private Sub Worksheet_Change(ByVal Target As Range) 'Your other change event code here MsgBox "Cell value changed!" End Sub Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) 'Your double-click event code here MsgBox "Double-clicked!" End Sub Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) 'Your right-click event code here MsgBox "Right-clicked!" End Sub Private Sub Worksheet_Activate() Application.EnableEvents = True End Sub Private Sub Worksheet_Deactivate() Application.EnableEvents = False End Sub Private Sub Workbook_Open() Application.EnableEvents = True End Sub