using enter to start a macro in from a userform instead of a command button

still learning

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

I’m using a command button in a userform to start a macro after data is entered in a text box
How do I modify or add to the code so I can use the enter key instead?
VBA Code:
Private Sub CommandButton1_Click()
    With TextBox1 
        ActiveSheet.Range("ae3").Value = .Text
     End With
    With TextBox2 
        ActiveSheet.Range("af3").Value = .Text
     End With
    With TextBox3  
        ActiveSheet.Range("ag3").Value = .Text
     End With
    With TextBox4  
        ActiveSheet.Range("ai3").Value = .Text
     End With
    With TextBox5 
        ActiveSheet.Range("aj3").Value = .Text
     End With
   With TextBox6 
        ActiveSheet.Range("al3").Value = .Text
     End With
 Me.Hide
End With
chchkfind
Unload Me
End Sub
Chckfind runs an advance filter using what is in the text box(es)



mike
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
How about setting the Default Property of the CommandButton to TRUE
 
Upvote 0
Hi Jaafar Tribak
Can you show me how?


mike

Select the commandbutton and change the Default Property to TRUE in the VBE Properties window.

If you want to do this at runtime, you can use this code :
VBA Code:
Private Sub UserForm_Initialize()
    Me.CommandButton1.Default = True
End Sub
 
Upvote 0
Thank you Jaafar Tribak
It worked like i wanted it to
Another learning experience

Stay safe with whats happening in the world

mike
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

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