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

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?

1 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}"
3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like