Execute code from a textbox by pressing Enter. Textbox is em

Tanner

New Member
Joined
May 8, 2002
Messages
11
I would like to press enter within a text box and have code execute. The textbox is inserted into Sheet1. Not on a user form.

Currently, I enter the text in a textbox and pressing enter does nothing. I placed a button next to the textbox and click it to execute the code. I think this should be simple, but I can't figure it out... Thanks, Stan.
This message was edited by Tanner on 2002-05-10 08:47
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi Tanner,
Assuming it is on an userform.
Why don't you use keydown event. Here is sample for you.

<code>
<pre>
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then Call YourMacro
End Sub

Private Sub YourMacro()
MsgBox "it works!"
End Sub
</pre>
</code>
 
Upvote 0
Thanks for the Solution, Colo. Your solution worked even though the textbox is embedded into sheet 1 and not on a user form.
 
Upvote 0

Forum statistics

Threads
1,213,558
Messages
6,114,297
Members
448,564
Latest member
ED38

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