userform to close using the enter key

still learning

Well-known Member
Joined
Jan 15, 2010
Messages
734
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

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

still learning

Well-known Member
Joined
Jan 15, 2010
Messages
734
Office Version
  1. 365
Platform
  1. Windows
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

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
4,627
Suggest you think of a different method. Assigning the ENTER key to do anything except enter data will lead to complete disaster.
 
Upvote 0

NoSparks

Well-known Member
Joined
Mar 15, 2013
Messages
1,479
Office Version
  1. 2010
Platform
  1. Windows
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

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
2,828
Office Version
  1. 2013
Platform
  1. Windows
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,195,600
Messages
6,010,651
Members
441,558
Latest member
lambierules

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