you can assign macros to shortcuts from the keyboard, if that is what you mean.
This is a discussion on Keyboard input within the Excel Questions forums, part of the Question Forums category; Is there a way, using a macro, to determine what a keyboard character is? Something like: If Keyboard input = ...
Is there a way, using a macro, to determine what a keyboard character is? Something like:
If Keyboard input = Char(13) Then
Do something
End If
you can assign macros to shortcuts from the keyboard, if that is what you mean.
Regards,
Zack Barresse
Excel & Access blog
All Excel Functions
Training
(If you would like comments in any code, please say so.)
No, that is not what I mean. I want to monitor keyboard inputs while entering into a text box and when the Enter key is found to have been depressed, do some things.
If you mean, can you run a macro after you've started to enter something into a cell, but before you hit the [Enter] key, then no. While in Edit mode you cannot execute a macro.
If you mean, can you trap for certain values having been entered into a cell after you hit the [Enter] key and you back out of Edit mode then yes, you can use the _Change() event handlers to take some action based on what was entered into a cell.
Greg
………………………………………………
Work: XL 2003, 2007 and 2010 on Windows 7
Please use CODE tags - especially for longer excerpts of code.
What I am trying to do is enter things into a TEXTBOX, not a cell. each keystroke will give a Change event. I want to look at each keyboard entry at that change event to determine if it was the enter key that was depressed. is this possible?
Maybe yes, maybe no; you need to clarify 2 points first:
(1)
What kind of TextBox are you talking about? AutoShape? Forms on sheet? ActiveX on sheet? Userform? What?
(2)
Why are you interested in the Enter key? Because it's the Enter key? Or because you want to monitor when the TextBox is exited? If so, what about the Tab key, which will also allow for TextBox exit? You might need an Exit event instead.
So you see, a little more info from you would go a long way to getting an answer.
thanks Tom, this is an active X, created from the Control ToolBox. It is not on a user form. I want to use the Enter key, because the standard for a completed entry is the enter key.
What do you mean by "the standard"? If they type in some gobbledy-gook and click some cell, that de facto enters the gobbledy-gook. Will that be OK for you, and you won't want to protect against that?
Look, I am trying to use a control box created text box to enter some data. I dont want to use it on a user form. I would like the user to be able to enter whatever they want, then press the enter key and have a macro then shift the focus of that control box created text box onto another one. All I am trying to find out is if this is possible and if so, how to do it. The change event for the text box detects any keystroke. At each change event, I would like to look at what that change was and then initiate code.
Here's the code for hitting Enter in a an ActiveX TextBox. The code goes in the worksheet module upon which the TextBox resides. Modify for name of TextBox.
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyReturn Then
MsgBox "It's your thang..." & vbCrLf & "Do whatcha wanna do...", 64, "Enter was clicked."
KeyCode = 0
End If
End Sub
Bookmarks