Text box and Enter Keys

gjadcock

New Member
Joined
Sep 17, 2002
Messages
27
I have been looking through the archives and cannot seem to get any of the example code working.

I have a text box which the user completes and a button which takes the value in the text box and passes this to a function that filters a list.

All I want to do is to do the same thing if the user presses either enter key

Thanks

:oops:
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
If your TextBox is from the Control Toolbox, something like this should work:

Code:
Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = 13 Then
        Range("A1").Select
'       Your code goes here
        MsgBox "Finished"
    End If
End Sub
 
Upvote 0
Andrew,

Works great, thanks.

As always, there is something else. If the text box search is invalid I have a message (vbExclamation) which tells me so, however if I now press enter to remove the message box and re-enter the search, I now re-submit the extg query. So I suppose I need to change the focus to the error message?? How do I do this??

Regards
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,384
Members
449,080
Latest member
Armadillos

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