Excel – How to run an event on Enter key in Excel VBA

microsoft excelvba

I'd like to have Excel change to a predefined data in any cell in column A whenever the user hits the Enter key (instead of the default go to next cell behavior). How can I achieve this in VBA?

Best Answer

Try do it in Workbook_open event

Private Sub Workbook_Open()
    Application.OnKey "{ENTER}", "MyEnterEvent"
End Sub

Sub MyEnterEvent

    ' codes here

End Sub

To end Macro

Application.OnKey "{ENTER}"
Related Question