Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
609 views
in Technique[技术] by (71.8m points)

excel vba enter key run macro

I'm sure this must be simple but for the life of me I can't find how to do it

How do I detect that the enter key has been pressed on a particular range of cell

I have a group of merged cells ($H$9:$K$13) which is basically a box which the user enters a number. I want to run a macro once the user presses enter (on the keyboard NOT the num keypad)

I cant find any examples on this. I can find example on doing this from a text box but not from a cell

I have tried Application.onkeys which works on key combinations but not on the enter key (it says tilde for enter key and ENTER for num pad but neither work)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Do you surely want to detect the press event of ENTER keys?

How do you think, if users used tab key to change the input of certain cells you noted in your post. Or selection range was changed because of mouse click leaving values in cell changed.

I'm little confused, because using Workbook.SheetChange Event you can run procedures for your purpose. Of course you can check the range changed was in the range you noted or not, in this event procedure using argument Target.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...