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
 

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Zack Barresse

MrExcel MVP
Joined
Dec 9, 2003
Messages
10,881
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
you can assign macros to shortcuts from the keyboard, if that is what you mean.
 

elgringo56

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

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,014
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.
 

elgringo56

Well-known Member
Joined
Apr 15, 2002
Messages
869

ADVERTISEMENT

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?
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,224
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.
 

elgringo56

Well-known Member
Joined
Apr 15, 2002
Messages
869

ADVERTISEMENT

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.
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,224
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?
 

elgringo56

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

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,224
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,906
Messages
5,598,783
Members
414,259
Latest member
beetle12

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
Top