Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Macro On Keystroke "ENTER" in Textbox 1

Status
Not open for further replies.

PugnaxX

Technical User
Jan 11, 2006
37
US
Hi All,

I've been developing worksheet that initially has all data hidden. The user enters search criteria into a textbox (inserted onto the worksheet from Control Toolbox) and then has to hit the Search button (inserted from Forms Toolbar) to run the search Macro. If you want further background see this thread:


I am trying to have it so that after entering text into the textbox, the user can simply hit ENTER to run the macro, so they won't have to use the mouse and click the button if they do not want to. I've been looking around and it seems the only info I can find is how to do this on a form not on a worksheet.

Any Ideas?

Thanks!

PugnaxX
 
Code:
Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

If KeyCode = 13 Then 'Enter key is 13
    RunMacroHere
End If

End Sub

Should do the job.

BD
 
Instead of the KeyUp, you could also use the KeyDown and KeyPress events.
 
THANKS bdmangum!!!!!!

That did do the job, it works great!

-PugnaxX
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top