userform to close using the enter key

still learning

Well-known Member
Joined
Jan 15, 2010
Messages
784
Office Version
  1. 365
Platform
  1. Windows
Hi

I have a userform that is used to enter a first name or a last name in textboxes
Then, when command button1 is clicked, the macro>>findd<< uses advance filter to find matches for either
If either name is not in the data, a message box comes up
How do I change, or add to, the macro so instead of clicking on the commonbutton, I can just hit enter
VBA Code:
Private Sub CommandButton1_Click()
With TextBox5
 'last name
ActiveSheet.Range("p2").Value = .Text
End With
With TextBox1
 'first name
ActiveSheet.Range("q2").Value = .Text
End With
Me.Hide
findd
Unload Me
If Range("ae2").Value = "" Then
MsgBox (" NO Results")
End If
End Sub

ALSO, is it possible to have a message box the can close without hitting OK


mike
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
opps
I didn't get the rest of the question in before i hit post
way back in march, i posted a similar question and can't remember why it didn't work. I didn't have time then to explore this further and forgot about it. I'm now updating the spreadsheet
Excel Max was very nice in posting a reply (Mar 16 of this year)
 
Upvote 0
Suggest you think of a different method. Assigning the ENTER key to do anything except enter data will lead to complete disaster.
 
Upvote 0
How about just hitting the Enter key like normal after typing something into a textbox
and using the textbox Exit event to click the Command Button
VBA Code:
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    CommandButton1_Click
End Sub

When your message box displays, the OK button is already selected, just hit the Enter key
 
Upvote 0
ALSO, is it possible to have a message box the can close without hitting OK
Would suggest not using a message box at all.
By adding a label to your userform to carry the message you have in mind, there's no need for hitting Enter or clicking an OK button.
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

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