Use enter key to start macro

GoodmanJim

Board Regular
Joined
Aug 24, 2003
Messages
95
I would like to start a macro when the person depresses the enter in a worksheet and not on the other worksheets in a workbook.

Thank you for your help in advance
Jim
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Code for the indicated event of the target worksheet.

Hope it helps.

Gary

Code:
Private Sub Worksheet_Activate()

'Run "MyMacro" when Enter (Return) key is pressed
Application.OnKey "{RETURN}", "MyMacro" ' Change name to suit

End Sub

Private Sub Worksheet_Deactivate()

'Restore Enter (Return) key to normal function
Application.OnKey "{ENTER}", ""

End Sub
 
Upvote 0
Gary,

I think the last line should be
Code:
Application.OnKey "{RETURN}"

As it is, I think you're disabling the Enter key on the numeric keypad.
 
Upvote 0
Yes. Thanks for the heads up.

I tried them both and failed to make the correction after I decided which one it should be.

My edit time has probably already expired.

Gary
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,823
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top