Keyboard input

elgringo56

Well-known Member
Joined
Apr 15, 2002
Messages
869
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
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
you can assign macros to shortcuts from the keyboard, if that is what you mean.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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?
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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?
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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